使用纯CSS而不是javascript或jquery的响应式菜单

时间:2013-08-19 04:55:58

标签: css

我正在使用纯css的下拉菜单。对于以下普通的css菜单代码,我需要一个良好的响应式下拉导航菜单。我需要使用纯css的响应,而不是在javascript或jquery中。

我正在尝试使用纯CSS执行响应,但我无法做到完美的。任何人请帮助我。提前致谢。

ul.menu{
float:right;
}

ul.menu > li{
float:left;
list-style:none;    
}

ul.menu > li.current-menu-item a{
background: #5C5C5C;
color:#fff; 
}

ul.menu > li > a{
padding: 31px;
display:block;  
text-decoration: none;
font-family: Arial, Helvetica, sans-serif;
color:#666666;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}

ul.menu > li > a:hover{
background: #5C5C5C;
color:#fff; 
}

ul.menu > li:hover > ul.sub-menu{
display:block;
visibility:visible;
list-style:none;
opacity:1;  
top: 108px; 
}

ul.menu > li > ul.sub-menu > li > a:hover{
background:#5C5C5C;
color:#fff; 
}

ul.menu > li > ul.sub-menu{
visibility:hidden;
position: absolute;
width: 200px;
z-index: 999;
list-style:none;    
background: #f9f9f9;
border: 1px solid #e9e9e9;
border-radius: 0 0 5px 5px;
border-bottom: 3px solid #757575;
top:40px;
opacity:0;  
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;  
}

ul.menu > li > ul.sub-menu > li > a{
padding: 15px;
display:block;
text-decoration: none;
font-family: Arial, Helvetica, sans-serif;
color:#666666;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
border-bottom: 1px solid #efefef;   
}

1 个答案:

答案 0 :(得分:0)

<div>
    <ul class="mymenu">
        <li><a class="dropdown" href="#">Menu 1</a>
            <ul>
                <li><a href="#">Sub-menu 1</a></li>
                <li><a href="#">Sub-menu 2</a></li>
                <li><a href="#">Sub-menu  3</a></li>
            </ul>
            </li>

    </ul>
</div>


div ul {
    -webkit-font-smoothing:antialiased;
    text-shadow:0 1px 0 #FFF;
    background: #ddd;
    list-style: none;
    margin: 0;
    padding: 0;
    width: 100%;
}
div li {
    float: left;
    margin: 0;
    padding: 0;
    position: relative;
    min-width: 25%;
}
div a {
    background: #ddd;
    color: #444;
    display: block;
    font: bold 16px/50px sans-serif;
    padding: 0 25px;
    text-align: center;
    text-decoration: none;
    -webkit-transition: all .25s ease;
       -moz-transition: all .25s ease;
        -ms-transition: all .25s ease;
         -o-transition: all .25s ease;
            transition: all .25s ease;
}
div .dropdown:after {
    content: ' ▶';
}
div .dropdown:hover:after{
    content:'\25bc'
}
div li:hover a {
    background: #ccc;
}
div li ul {
    float: left;
    left: 0;
    opacity: 0;
    position: absolute;
    top: 35px;
    visibility: hidden;
    z-index: 1;
    -webkit-transition: all .25s ease;
       -moz-transition: all .25s ease;
        -ms-transition: all .25s ease;
         -o-transition: all .25s ease;
            transition: all .25s ease;
}
div li:hover ul {
    opacity: 1;
    top: 50px;
    visibility: visible;
}
div li ul li {
    float: none;
    width: 100%;
}
div li ul a:hover {
    background: #bbb;
}

/* Clearfix */

.mymenu:after, .cf:before {
    content:"";
    display:table;
}
.mymenu:after {
    clear:both;
}
.mymenu {
    zoom:1;
}