CSS |响应式菜单

时间:2013-08-16 07:05:21

标签: css menu responsive-design

我有一个菜单结构:

<ul id="nav_menu">
    <li><a href="#!index?category_id=3" class="subcategory">Electronics</a>
        <ul>
            <li><a href="#!index?category_id=15">Mobile phones</a></li>
        </ul>
    </li>
    <li><a href="#!index?category_id=4">Computers</a></li>
    <li><a href="#!index?category_id=5">Car Electronics</a></li>
    <li><a href="#!index?category_id=6">TV &amp; Video</a></li>
    <li><a href="#!index?category_id=7">Cell Phones</a></li>
    <li><a href="#!index?category_id=8">MP3 Players</a></li>
    <li><a href="#!index?category_id=9">Cameras &amp; Photo</a></li>
    <li><a href="#!index?category_id=10">Apparel</a></li>
    <li><a href="#!index?category_id=11">Music</a></li>
    <li><a href="#!index?category_id=12">Movies &amp; TV</a></li>
    <li><a href="#!index?category_id=13">Video Games</a></li>
    <li><a href="#!index?category_id=14">Office Supplies</a></li>
</ul>

但它看起来如下:

enter image description here

如果我有很多类别且设备屏幕宽度很窄,是否可以优化菜单?

我的CSS:

#nav_menu li {
    display: inline;
    float: left;
    padding-right: 3px;
    position: relative;
}

#nav_menu > li > a {
    background: none repeat scroll 0 0 #404040;
    border-radius: 3px 3px 0 0;
    color: #FFFFFF;
    display: block;
    font-size: 14px;
    font-weight: bold;
    height: 28px;
    line-height: 28px;
    padding: 0 5px;
    text-decoration: none;
}
#nav_menu ul {
    background: none repeat scroll 0 0 #404040;
    box-shadow: 0 0 1px rgba(0, 0, 0, 0.1);
    list-style: none outside none;
    margin: 0;
    padding: 5px;
    position: absolute;
    top: 36px;
    width: 140px;
    z-index: 2;
}

2 个答案:

答案 0 :(得分:1)

喜欢这个

<强> DEMO

<强> CSS

#nav_menu ul{
    margin:0;
    padding:0;
    float:left;
}
#nav_menu li {
    display: inline;
    float: left;
    padding-right: 3px;
    position: relative;
     border-bottom:#FFD700 3px solid;
}

#nav_menu > li > a {
    background: none repeat scroll 0 0 #404040;
    border-radius: 3px 3px 0 0;
    color: #FFFFFF;
    display: block;
    font-size: 14px;
    font-weight: bold;
    line-height: 20px;
    padding: 0 5px;
    text-decoration: none;


}
#nav_menu ul {
    background: none repeat scroll 0 0 #404040;
    box-shadow: 0 0 1px rgba(0, 0, 0, 0.1);
    list-style: none outside none;
    margin: 0;
    padding: 5px;
    position: absolute;
    top: 20px;
    width: 140px;
    z-index: 2;
}

答案 1 :(得分:0)

prueba lo siguiente:

<强> DEMO 1

<强> JAVASCRIPT

$(document).ready(function()
{
    $("div.po").set_ELEMENT(
    {
        bgColor:'red',

        click: function(oThis)
        {
            oThis.find('> div').css({'color':'red','background-color' : 'blue'});
        }
     });
});