Revamp menus

This commit makes .pure-menu smaller, more responsive, and easier to customize.

- Remove `.pure-menu-open`
- Remove dropdown menu CSS
- Add `.pure-menu-responsive` and `.pure-menu-toggle` to
  make responsive horizontal menus.
- Make pure menus *really* easy to customize
This commit is contained in:
Tilo Mitra 2013-07-19 13:28:46 -04:00
parent 1d3314e4a0
commit d20590c6e5
4 changed files with 177 additions and 200 deletions

View File

@ -1,44 +1,20 @@
/*csslint adjoining-classes:false, outline-none:false*/ /*csslint adjoining-classes: false, box-model:false*/
/*TODO: Remove this lint rule override after a refactor of this code.*/ .pure-menu ul, .pure-menu li {
position: relative;
.pure-menu ul {
position: absolute;
visibility: hidden;
} }
.pure-menu.pure-menu-open {
visibility: visible;
z-index: 2;
width: 100%;
}
.pure-menu ul { .pure-menu ul {
left: -10000px;
list-style: none; list-style: none;
margin: 0; margin: 0;
padding: 0; padding: 0;
top: -10000px;
z-index: 1;
} }
.pure-menu li {
.pure-menu > ul { position: relative; } padding: 0;
margin: 0;
.pure-menu-open > ul { height: 100%;
left: 0;
top: 0;
visibility: visible;
} }
.pure-menu-open > ul:focus {
outline: 0;
}
.pure-menu li { position: relative; }
.pure-menu a, .pure-menu a,
.pure-menu .pure-menu-heading { .pure-menu .pure-menu-heading {
display: block; display: block;
color: inherit;
line-height: 1.5em; line-height: 1.5em;
padding: 5px 20px; padding: 5px 20px;
text-decoration: none; text-decoration: none;
@ -52,42 +28,19 @@
margin: 0; margin: 0;
vertical-align: middle; vertical-align: middle;
} }
.pure-menu.pure-menu-horizontal > ul { .pure-menu-horizontal > ul {
display: inline-block; display: inline-block;
*display: inline; *display: inline;
zoom: 1; zoom: 1;
vertical-align: middle; vertical-align: middle;
height: 2.4em;
} }
.pure-menu li a { padding: 5px 20px; } .pure-menu li a { padding: 5px 20px; }
.pure-menu-can-have-children > .pure-menu-label:after {
content: '\25B8';
float: right;
/* These specific fonts have the Unicode char we need. */
font-family: 'Lucida Grande', 'Lucida Sans Unicode', 'DejaVu Sans', sans-serif;
margin-right: -20px;
margin-top: -1px;
}
.pure-menu-can-have-children > .pure-menu-label { .pure-menu-can-have-children > .pure-menu-label {
padding-right: 30px; padding-right: 30px;
} }
.pure-menu-separator {
background-color: #dfdfdf;
display: block;
height: 1px;
font-size: 0;
margin: 7px 2px;
overflow: hidden;
}
.pure-menu-hidden {
display: none;
}
/* FIXED MENU */ /* FIXED MENU */
.pure-menu-fixed { .pure-menu-fixed {
position: fixed; position: fixed;
@ -97,7 +50,12 @@
} }
/* HORIZONTAL MENU CODE */ /* HORIZONTAL MENU */
.pure-menu-horizontal {
width: 100%;
border-left: none;
border-right: none;
}
/* Initial menus should be inline-block so that they are horizontal */ /* Initial menus should be inline-block so that they are horizontal */
.pure-menu-horizontal li { .pure-menu-horizontal li {
@ -112,26 +70,50 @@
display: block; display: block;
} }
/* Content after should be down arrow */
.pure-menu-horizontal > .pure-menu-children > .pure-menu-can-have-children > .pure-menu-label:after {
content: "\25BE";
}
/*Add extra padding to elements that have the arrow so that the hover looks nice */
.pure-menu-horizontal > .pure-menu-children > .pure-menu-can-have-children > .pure-menu-label {
padding-right: 30px;
}
/* Adjusting separator for vertical menus */ /* Adjusting separator for vertical menus */
.pure-menu-horizontal li.pure-menu-separator { .pure-menu-horizontal .pure-menu-separator {
height: 50%; height: 50%;
width: 1px; width: 1px;
margin: 0 7px; margin: 0 7px;
} }
/* Submenus should be horizontal separator again */ /* Submenus should be horizontal separator again */
.pure-menu-horizontal li li.pure-menu-separator { .pure-menu-horizontal li .pure-menu-separator {
height: 1px; height: 1px;
width: auto; width: auto;
margin: 7px 2px; margin: 7px 2px;
} }
/* RESPONSIVE MENUS */
/* Hide the toggle button by default. It will show on small screen sizes */
.pure-menu-responsive .pure-menu-toggle {
float: right;
text-transform: uppercase;
font-size: 80%;
display: none;
}
/* If the menu is open, and the viewport is larger than 767px, we
still want the toggle button to show.
*/
.pure-menu-responsive.pure-menu-active .pure-menu-toggle {
display: block;
}
.pure-menu-responsive .pure-menu-toggle:after {
content: "\25BE";
float: right;
/* These specific fonts have the Unicode char we need. */
font-family: 'Lucida Grande', 'Lucida Sans Unicode', 'DejaVu Sans', sans-serif;
margin-right: -15px;
margin-top: -1px;
}
.pure-menu-responsive.pure-menu-active ul, .pure-menu-responsive.pure-menu-active li {
display: block;
}
.pure-menu-responsive.pure-menu-active .pure-menu-separator {
width: auto;
height: 1px;
}

View File

@ -1,10 +1,16 @@
@media (max-width: 480px) { /*adjoining-classes: false*/
.pure-menu-horizontal { @media (max-width: 767px) {
width: 100%; .pure-menu-responsive .pure-menu-toggle {
display: block;
}
.pure-menu-responsive ul {
display: none;
}
.pure-menu-responsive.pure-menu.active ul {
display: inline-block;
*display: inline;
zoom: 1;
vertical-align: middle;
} }
.pure-menu-children li {
display: block;
border-bottom: 1px solid black;
}
} }

View File

@ -1,77 +1,44 @@
/*csslint adjoining-classes:false*/ /*csslint adjoining-classes: false, duplicate-properties:false*/
/*TODO: Remove this lint rule override after a refactor of this code.*/
/* MAIN MENU STYLING */
.pure-menu.pure-menu-open,
.pure-menu.pure-menu-horizontal li .pure-menu-children {
background: #fff; /* Old browsers */
border: 1px solid #b7b7b7;
}
/* remove borders for horizontal menus */
.pure-menu.pure-menu-horizontal,
.pure-menu.pure-menu-horizontal .pure-menu-heading {
border: none;
}
/* LINK STYLES */
.pure-menu a {
border: 1px solid transparent;
border-left: none;
border-right: none;
}
.pure-menu a,
.pure-menu .pure-menu-can-have-children > li:after {
color: #777;
}
.pure-menu .pure-menu-can-have-children > li:hover:after {
color: #fff;
}
/* MENUS STYLING */
/* Focus style for a dropdown menu-item when the parent has been opened */ /* Focus style for a dropdown menu-item when the parent has been opened */
.pure-menu .pure-menu-open { .pure-menu {
background: #dedede; background: #fff; /* need this to make menus stand out from page background */
border: 1px solid #eee;
} }
.pure-menu a {
color: #666;
}
/* Hover and focus styles */
.pure-menu li a:hover, .pure-menu li a:hover,
.pure-menu li a:focus { .pure-menu li a:focus {
background: #eee; background: #dedede;
*background: #dedede;
background: rgba(0,0,0,0.15);
} }
/* DISABLED STATES */ /* DISABLED STATES */
.pure-menu li.pure-menu-disabled a:hover, /* need the .pure-menu prefix so that people over-riding `a` don't over-ride pure-menu-disabled too */
.pure-menu li.pure-menu-disabled a:focus { .pure-menu .pure-menu-disabled a,
background: #fff; .pure-menu .pure-menu-disabled a:hover,
color: #bfbfbf; .pure-menu .pure-menu-disabled a:focus {
color: #bababa;
*color: #bababa;
color: rgba(0,0,0, 0.5);
background: transparent;
} }
.pure-menu .pure-menu-disabled > a {
background-image: none;
border-color: transparent;
cursor: default;
}
.pure-menu .pure-menu-disabled > a, .pure-menu-heading {
.pure-menu .pure-menu-can-have-children.pure-menu-disabled > a:after {
color: #bfbfbf;
}
/* HEADINGS */
.pure-menu .pure-menu-heading {
color: #565d64; color: #565d64;
text-transform: uppercase; text-transform: uppercase;
font-size: 90%; font-size: 90%;
margin-top: 0.5em; margin-top: 0.5em;
border-bottom-width: 1px; border-bottom: 1px solid #eee;
border-bottom-style: solid; }
border-bottom-color: #dfdfdf;
.pure-menu-horizontal .pure-menu-heading {
border-bottom: none;
} }
/* ACTIVE MENU ITEM */ /* ACTIVE MENU ITEM */
@ -80,7 +47,9 @@
} }
/* FIXED MENU */ /* FIXED MENU */
.pure-menu.pure-menu-open.pure-menu-fixed { .pure-menu-fixed {
border: none; border: none;
border-bottom: 1px solid #b7b7b7; border-bottom: 1px solid #b7b7b7;
*border-bottom: 1px solid #b7b7b7;
border-bottom: 1px solid rgba(0,0,0,0.4);
} }

View File

@ -41,6 +41,32 @@
margin-bottom:15px; margin-bottom:15px;
} }
.pure-menu-custom {
background: red;
border:1px solid black;
}
.pure-menu-custom a {
color: white;
}
.pure-menu-custom a:hover {
color: orange;
}
.pure-menu-custom .pure-menu-disabled a,
.pure-menu-custom .pure-menu-disabled a:hover
{
color: yellow;
}
.pure-menu-custom .pure-menu-heading {
color: blue;
}
.pure-menu-custom .pure-menu-selected {
font-weight: bold;
}
</style> </style>
</head> </head>
<body class="pure-skin-sam"> <body class="pure-skin-sam">
@ -60,7 +86,7 @@
You can mark the active menu element by adding the <code>.pure-menu-selected</code> class to the list item. You can mark the active menu element by adding the <code>.pure-menu-selected</code> class to the list item.
</p> </p>
<div class="pure-menu pure-menu-open pure-menu-horizontal"> <div class="pure-menu pure-menu-horizontal">
<a href="#" class="pure-menu-heading">Site Title</a> <a href="#" class="pure-menu-heading">Site Title</a>
<ul> <ul>
<li><a href="#">Home</a></li> <li><a href="#">Home</a></li>
@ -74,7 +100,7 @@
<h2>Vertical Menu</h2> <h2>Vertical Menu</h2>
<div id="vertical-menu1" class="pure-menu pure-menu-open"> <div id="vertical-menu1" class="pure-menu">
<a href="#" class="pure-menu-heading">Site Title</a> <a href="#" class="pure-menu-heading">Site Title</a>
<ul> <ul>
<li class="pure-menu-selected"><a href="#">Home</a></li> <li class="pure-menu-selected"><a href="#">Home</a></li>
@ -87,7 +113,7 @@
</ul> </ul>
</div> </div>
<div id="vertical-menu1" class="pure-menu pure-menu-open"> <div id="vertical-menu1" class="pure-menu">
<ul> <ul>
<li class="pure-menu-heading">Site Title</li> <li class="pure-menu-heading">Site Title</li>
<li class="pure-menu-selected"><a href="#">Home</a></li> <li class="pure-menu-selected"><a href="#">Home</a></li>
@ -101,44 +127,6 @@
</div> </div>
<h2>Add Dropdowns to Menus</h2>
<p>
Adding dropdowns to menus requires the use of JavaScript. The <code>Y.Menu</code> module adds dropdown functionality and the ability to create JavaScript menus. It uses <code>csslist</code> to style these menus, so they look identical.
</p>
<div id="horizontal-menu">
<a href="#" class="pure-menu-heading">Site Title</a>
<ul id="std-menu-items">
<li class="pure-menu-selected"><a href="#">Flickr</a></li>
<li><a href="#">Messenger</a></li>
<li><a href="#">Sports</a></li>
<li><a href="#">Finance</a></li>
<li class="pure-menu-separator"></li>
<li>
<a href="#">Other</a>
<ul>
<li class="pure-menu-heading">More from Yahoo!</li>
<li class="pure-menu-separator"></li>
<li><a href="#">Autos</a></li>
<li><a href="#">Flickr</a></li>
<li><a href="#">Answers</a></li>
<li>
<a href="#">Even More</a>
<ul>
<li><a href="#">Horoscopes</a></li>
<li><a href="#">Games</a></li>
<li><a href="#">Jobs</a></li>
<li><a href="#">OMG</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<h2>Fixed Menus</h2> <h2>Fixed Menus</h2>
<p> <p>
@ -158,6 +146,39 @@
</ul> </ul>
</div> </div>
<h2>Responsive Menu</h2>
<div class="pure-menu pure-menu-horizontal pure-menu-2 pure-menu-responsive">
<a href="#" class="pure-menu-heading">Site Title</a>
<a href="#" class="pure-menu-toggle">Open</a>
<ul>
<li class="pure-menu-selected"><a href="#">Home</a></li>
<li><a href="#">Flickr</a></li>
<li><a href="#">Messenger</a></li>
<li class="pure-menu-separator">&nbsp;</li>
<li class="pure-menu-disabled"><a href="#">Sports</a></li>
<li><a href="#">Finance</a></li>
</ul>
</div>
<h2>Customizing Menu</h2>
<div class="pure-menu pure-menu-horizontal pure-menu-custom pure-menu-responsive">
<a href="#" class="pure-menu-heading">Site Title</a>
<a href="#" class="pure-menu-toggle">Open</a>
<ul>
<li class="pure-menu-selected"><a href="#">Home</a></li>
<li><a href="#">Flickr</a></li>
<li><a href="#">Messenger</a></li>
<li class="pure-menu-separator">&nbsp;</li>
<li class="pure-menu-disabled"><a href="#">Sports</a></li>
<li><a href="#">Finance</a></li>
</ul>
</div>
<h2>Paginator</h2> <h2>Paginator</h2>
<ul class="pure-paginator"> <ul class="pure-paginator">
@ -173,29 +194,28 @@
</div> </div>
<script src="http://yui.yahooapis.com/3.10.1/build/yui/yui-min.js"></script> <script src="http://yui.yahooapis.com/3.10.1/build/yui/yui-min.js"></script>
<script> <script>
var Y = YUI({ YUI({
fetchCSS: false,
classNamePrefix: 'pure' classNamePrefix: 'pure'
}).use('gallery-sm-menu', 'event-tap', 'node-base', function (Y) { }).use('node-base', function (Y) {
var toggle = Y.all(".pure-menu-toggle"),
i = 0,
ACTIVE = 'pure-menu-active';
//Y.config.classNamePrefix = 'pure'; for (; i < toggle.size(); i++) {
var horizontalMenu = new Y.Menu({ toggle.item(i).on('click', function (e) {
container: '#horizontal-menu', var parent = e.currentTarget.get('parentNode');
sourceNode: '#std-menu-items',
orientation: 'horizontal',
hideOnOutsideClick: false
});
horizontalMenu.render();
horizontalMenu.show();
Y.one('#showFixedMenuBtn').on('tap', function (e) {
var fixedMenu = Y.one('#fixed-menu');
fixedMenu.toggleClass('pure-menu-open');
});
e.preventDefault();
parent.toggleClass(ACTIVE);
if (parent.hasClass(ACTIVE)) {
e.currentTarget.set('text', 'Close');
}
else {
e.currentTarget.set('text', 'Open')
}
});
}
}); });
</script> </script>
</body> </body>