Variable Visions

Articles CSS CSS-Dropdown-Menu


tutorials - CSS and Web-Development.

CSS Dropdown Menu

Published Mon. Sep. 24, 2012


 

 

Read more on Responsive Menus and jQuery Here

/* Styles a horizontal dropdown menu on hover */

ul#mainmenu, ul#mainmenu * {
    margin:    0;
    padding:0;
    list-style:    none;
    position: relative;
    z-index:8;
    background-color: #dd7a04;
}
ul#mainmenu li {
    float:left;
    position:relative;
}
ul#mainmenu li:hover {
    visibility:    inherit; /* IE7 */
}
ul#mainmenu a {
    display:block;
    position:relative;
}
/* HIDE THE NESTED UL BY POSITIONING IT -999em OFF THE SCREEN */
ul#mainmenu ul {
    position:absolute;
    top:-999em;
    width:14em;
}
ul#mainmenu ul li {
    float: left;
    display: inline-block;
    width:100%;
}
ul#mainmenu li ul{
    background:    #FFFFFF !important;
    box-shadow: 0 5px 7px rgba(0, 0, 0, .3);
}
ul#mainmenu li ul li {
    text-align: left;
    font-size: 12px;
}
ul#mainmenu li li a{
    padding: 8px 10px;
    border: 0;
    border-bottom: 1px solid #E8E8E8;
    color: #636363;
     /* background: transparent; */
    background: #E2DFD8;
}

ul#mainmenu li.sfHover a.menulevel0,
ul#mainmenu li a.menulevel0:hover,
ul#mainmenu li a.menulevel0.menuitemselected,
ul#mainmenu li.itemselected > a.menulevel0,
ul#mainmenu li:hover > a.menulevel0 {
    background: -moz-linear-gradient(top, #333, #666);
    background: -webkit-gradient(linear, left top, left bottom, from(#333), to(#666));
    background-image: -o-linear-gradient(rgb(51,51,51),rgb(150,150,150));
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#333333', endColorstr='#666666');
    zoom: 1;
    /*     background: #333;  */
}
ul#mainmenu li.sfHover a li a,
ul#mainmenu li li a:hover{
    background: #FFF;
    color: #444444;
}




/* DROP DOWN */
#mainmenu li:hover ul,
#mainmenu li.sfHover ul {
    left:0;
    top:100%;
    z-index:99;
}
ul#mainmenu li:hover li ul,
ul#mainmenu li.sfHover li ul {
    top:-999em;
}
ul#mainmenu li li:hover ul,
ul#mainmenu li li.sfHover ul {
    left:100%;
    top:0;
}
ul#mainmenu li li:hover li ul,
ul#mainmenu li li.sfHover li ul {
    top: -999em;
}
ul#mainmenu li li li:hover ul,
ul#mainmenu li li li.sfHover ul {
    left: 100%;
    top: 0;
}


























@media screen and (max-width: 1024px)  {



/* DEACTIVATE THE DROP DOWN */
#mainmenu li:hover ul, #mainmenu li.sfHover ul {
    top:-999em !important;
}

/* CONVERT HORIZONTAL DROPDOWN MENU ON HOVER TO RESPSONSIVE DROP DOWN MENU ON CLICK */
ul#mainmenu {
    width: 100%;
    height: 0px !important;
    overflow: hidden !important;
}
ul#mainmenu.mainmenuclass2 {
    height: auto !important;
    overflow: visible !important;
}
/* CHANGE THE ORIGINAL POSITIONING OF THE NESTED UL TO STATIC */
ul#mainmenu ul{
    width: 100%;
    position: static;
    display: none;
}
/* CLEAR THE FLOATED LIST ITEMS TO CHANGE FROM HORIZONTAL TO VERTICAL MENU */
ul#mainmenu li{
    float: none;
    text-align: left;
    width: 100%;
}
ul#mainmenu li a{
    padding: 10px !important;
    border-bottom: 1px solid #FFF!important;
    display: block;
}
.mainmenucontainer2button {
    display: block;
    color: #FFF;
    background: url(/getfile.php/1979270.2131.vqcuttrsxb/arrow-sprite.png) no-repeat right -21px #DD7A04;
    padding-left: 10px;
    min-height: 40px;
}
.mainmenucontainer2button.buttonstate2 {
    background-position: right 9px;
}
.menubutton2{
    float: right;
    height: 20px;
    width: 40%;
    background: url(/getfile.php/1979270.2131.vqcuttrsxb/arrow-sprite.png) no-repeat right -31px transparent !important;
}
.menubutton2.revealbuttonstate2 {
    background-position: right -3px !important;
}
#mainmenu li:hover a {
    color: #333 !important;
}
.mainmenucontainer2button #path {
    display: block;
    width: 70%;
    margin-top: 0px;
    margin-bottom: 0px !important;
}
.mainmenucontainer2button #path a {
    color: #FFF !important;   
}
ul#mainmenu li:nth-child(even) {background: #efeded;}
ul#mainmenu li:nth-child(odd) {background: #e8e5e5;}