Skip to content

Instantly share code, notes, and snippets.

@zhilinskiy
Created January 24, 2013 10:13
Show Gist options
  • Save zhilinskiy/4619553 to your computer and use it in GitHub Desktop.
Save zhilinskiy/4619553 to your computer and use it in GitHub Desktop.
CSS: Responsive CSS gorizontal menu
/*======================================================
= Responsive CSS gorizontal menu =
======================================================*/
/**
*
* http://webdesignerwall.com/tutorials/css-responsive-navigation-menu
* Internet Explorer Support
* <!--[if lt IE 9]>
<script src="http://css3-mediaqueries-js.googlecode.com/files/css3-mediaqueries.js"></script>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
* HTML Markup
* <nav class="nav">
<ul>
<li class="current"><a href="#">Portfolio</a></li>
<li><a href="#">Illustration</a></li>
<li><a href="#">Web Design</a></li>
<li><a href="#">Print Media</a></li>
<li><a href="#">Graphic Design</a></li>
</ul>
</nav>
**/
/* nav */
.nav {
margin: 20px 0;
}
.nav ul {
margin: 0;
padding: 0;
}
.nav li {
margin: 0 5px 10px 0;
padding: 0;
list-style: none;
display: inline-block;
}
.nav a {
padding: 3px 12px;
text-decoration: none;
color: #999;
line-height: 100%;
}
.nav a:hover {
color: #000;
}
.nav .current a {
background: #999;
color: #fff;
border-radius: 5px;
}
/*Center and Right Alignment
you can change the alignment of the buttons by using text-align property.*/
/* right nav */
/*.nav.right ul {
text-align: right;
}
*/
/* center nav */
/*.nav.center ul {
text-align: center;
}
*/
/*Responsive
On 600px breakpoint, I set the nav element to relative position so I can place the
<ul> menu list on top with absolute position. I hide all <li> elements by specifying
display:none, but keep the .current <li> displaying as block. Then on the nav hover,
I set all <li> back to display:block (this will produce the dropdown list result).
I added a check icon graphic on the .current element to indicate it is the active item.
For the center and right alignment menu, use left and right property to position the <ul> list. */
@media screen and (max-width: 600px) {
.nav {
position: relative;
min-height: 40px;
}
.nav ul {
width: 180px;
padding: 5px 0;
position: absolute;
top: 0;
left: 0;
border: solid 1px #aaa;
background: #fff url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUg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jU0QUE2QkVDQzI2RDZGRiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/Pvb/uPAAAAAmSURBVHjaYmRgYPBlIBGwiIuLk6qHgfH///+DWdNoQNA7IAACDABm7hO6FUUnoQAAAABJRU5ErkJggg==) no-repeat 10px 11px;
border-radius: 5px;
box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.nav li {
display: none; /* hide all <li> items */
margin: 0;
}
.nav .current {
display: block; /* show only current <li> item */
}
.nav a {
display: block;
padding: 5px 5px 5px 32px;
text-align: left;
}
.nav .current a {
background: none;
color: #666;
}
/* on nav hover */
.nav ul:hover {
background-image: none;
}
.nav ul:hover li {
display: block;
margin: 0 0 5px;
}
.nav ul:hover .current {
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAALCAYAAABLcGxfAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6RjIyQkFFNkI1Q0Y3MTFFMkI1NEFBNkJFQ0MyNkQ2RkYiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6RjIyQkFFNkM1Q0Y3MTFFMkI1NEFBNkJFQ0MyNkQ2RkYiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpGMjJCQUU2OTVDRjcxMUUyQjU0QUE2QkVDQzI2RDZGRiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpGMjJCQUU2QTVDRjcxMUUyQjU0QUE2QkVDQzI2RDZGRiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PqD6KfQAAACZSURBVHjaYmYgDrABsSoQf2UhQjE3ECtD2f+YCSgWRFJ8C4h/4rNBDIhlQaYC8W0g/gESBNkgBVXwC0ozQhWCxP8D8X0g/gwzBaRBHojFgZgViL8BsRIQC0HlnwLxW2RrGaHuVMLipDdA/BBdkBnqNhDNgyT+FYjvYfMYLJQ+QzWwA/FvaIj8JRTeID/oQsOdaMBESAFAgAEAuJsXuNqs7O4AAAAASUVORK5CYII=) no-repeat 10px 7px;
}
/* right nav */
/* .nav.right ul {
left: auto;
right: 0;
}*/
/* center nav */
/* .nav.center ul {
left: 50%;
margin-left: -90px;
}*/
}
/*----- End of Responsive CSS gorizontal menu ------*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment