简体   繁体   English

折叠和展开在CSS中不起作用

[英]Collapse and Expand not working in css

I have a side bar menu there are items home, gallery , who is the best and competition. 我有一个侧边栏菜单,其中有首页,画廊,最佳和竞争项目。

There is a collapse and expand drop down for gallery and who is the best and that are working properly.There in the competition tab a dropdown name toplist this week, and the toplist this week have another drop down of 5 items.I want that like gallery when i clik the competition the toplist this week appear and when i click the toplist this week the items appear and like gallery there be expand and collapse. 有一个画廊的崩溃和扩展下拉列表,谁是最好的并且正在正常运行。在比赛选项卡中,本周的下拉列表名称为Toplist,而本周的顶级列表还有另外5个下拉列表。当我点击比赛时,画廊会出现在本周的榜单上,当我点击这个星期的榜单时,这些物品就会出现,并且像画廊一样会展开和折叠。

HTML: HTML:

<ul id="nav">
    <li><a href="index.php"><img src="images/home.png"/> Home</a></li>
    <li><a href="#" class="sub" tabindex="1"><img src="images/categories.png"/>Gallery</a><img src="images/up.gif" alt=""/>
    <ul>
        <li><a href="cars.php"><img src="images/cars.png"/>Cars</a></li>
        <li><a href="movies.php"><img src="images/movies.png"/>Movies</a></li>
        <li><a href="babies.php"><img src="images/baby.jpg"/>Babies</a></li>
        <li><a href="puppies.php"><img src="images/puppies.png"/>Puppies</a></li>
    </ul>
    </li>
    <li><a href="#" class="sub" tabindex="1"><img src="images/best.png"/>Who is the best</a><img src="images/up.gif" alt=""/>
    <ul>
        <li><a href="#"><img src="images/voteforcars.png"/>Vote for Cars</a></li>
        <li><a href="#"><img src="images/voteforsport.png"/>Vote for Sports</a></li>
        <li><a href="#"><img src="images/voteformovies.jpg"/>Vote for Movies</a></li>
    </ul>
    <li><a href="#" class="sub" tabindex="1"><img src="images/toplits.png"/>Competition</a><img src="images/up.gif" alt=""/>
    <ul>
        <li><a href="#" class="sub" tabindex="1"><img src="images/top.jpg"/>Toplists of Weak</a><img src="images/up.gif" alt=""/>
        <ul>
            <li><a href="#"><img src="images/sports.png"/>Sports</a></li>
            <li><a href="#"><img src="images/cars.png"/>Cars</a></li>
            <li><a href="#"><img src="images/movies.png"/>Movies</a></li>
            <li><a href="#"><img src="images/images.png"/>Images</a></li>
            <li><a href="#"><img src="images/baby.jpg"/>Babies</a></li>
        </ul>
        </li>
    </ul>

CSS: CSS:

#nav {
    border-radius: 3px;
    -moz-border-radius: 3px;
    -webkit-border-radius: 3px;
}

#nav, #nav ul {
    list-style: none;
    padding: 0;
    width: 199px;
}

#nav ul {
    position: relative;
    z-index: -1;
}

#nav li {
    position: relative;
    z-index: 100;
}

#nav ul li {
    margin-top: -23px;
    -moz-transition: 0.4s linear 0.4s;
    -ms-transition: 0.4s linear 0.4s;
    -o-transition: 0.4s linear 0.4s;
    -webkit-transition: 0.4s linear 0.4s;
    transition: 0.4s linear 0.4s;
}

#nav li a {
    background-color: #d4d5d8;
    color: #000;
    display: block;
    font-size: 12px;
    font-weight: bold;
    line-height: 28px;
    outline: 0;
    padding-left: 15px;
    text-decoration: none;
}

#nav li a.sub {
    background: #d4d5d8 url("../images/down.gif") no-repeat;
}

#nav li a + img {
    cursor: pointer;
    display: none;
    height: 28px;
    left: 0;
    position: absolute;
    top: 0;
    width: 200px;
}

#nav li a img {
    border-width: 0px;
    height: 24px;
    line-height: 28px;
    margin-right: 8px;
    vertical-align: middle;
    width: 24px;
}

#nav li a:hover {
    background-color: #bcbdc1;
}

#nav ul li a {
    background-color: #eee;
    border-bottom: 1px solid #ccc;
    color: #000;
    font-size: 11px;
    line-height: 22px;
}

#nav ul li a:hover {
    background-color: #ddd;
    color: #444;
}

#nav ul li a img {
    background: url("images/bulb.png") no-repeat;
    border-width: 0px;
    height: 16px;
    line-height: 22px;
    margin-right: 5px;
    vertical-align: middle;
    width: 16px;
}

#nav ul li:nth-child(odd) a img {
    background: url("images/bulb2.png") no-repeat;
}

#nav a.sub:focus {
    background: #bcbdc1;
    outline: 0;
}

#nav a:focus ~ ul li {
    margin-top: 0;
    -moz-transition: 0.4s linear;
    -ms-transition: 0.4s linear;
    -o-transition: 0.4s linears;
    -webkit-transition: 0.4s linears;
    transition: 0.4s linear;
}

#nav a:focus + img, #nav a:active + img {
    display: block;
}

#nav a.sub:active {
    background: #bcbdc1;
    outline: 0;
}

#nav a:active ~ ul li {
    margin-top: 0;
}

#nav ul:hover li {
    margin-top: 0;
}

jsFiddle here: http://jsfiddle.net/502n03eL/ jsFiddle在这里: http : //jsfiddle.net/502n03eL/

You can try this css this might be work 您可以尝试此CSS这可能是工作

#nav {

     border-radius:3px;
    -moz-border-radius:3px;
    -webkit-border-radius:3px;
}
#nav, #nav ul, #nav ul ul {
    list-style:none;
    padding:0;
    width:199px;
}
#nav ul, #nav ul ul {
    position:relative;
    z-index:-1;
}
#nav li {
    position:relative;
    z-index:100;
}
#nav ul li, #nav ul ul li {
    margin-top:-23px;

    -moz-transition:  0.4s linear 0.4s;
    -ms-transition: 0.4s linear 0.4s;
    -o-transition: 0.4s linear 0.4s;
    -webkit-transition: 0.4s linear 0.4s;
    transition: 0.4s linear 0.4s;
}
#nav li a {
    background-color:#d4d5d8;
    color:#000;
    display:block;
    font-size:12px;
    font-weight:bold;
    line-height:28px;
    outline:0;
    padding-left:15px;
    text-decoration:none;
}
#nav li a.sub {
    background:#d4d5d8 url("../images/down.gif") no-repeat;
}

#nav li a + img {
    cursor:pointer;
    display:none;
    height:28px;
    left:0;
    position:absolute;
    top:0;
    width:200px;
}
#nav li a img {
    border-width:0px;
    height:24px;
    line-height:28px;
    margin-right:8px;
    vertical-align:middle;
    width:24px;
}
#nav li a:hover {
    background-color:#bcbdc1;
}
#nav ul li a, #nav ul ul li a {
    background-color:#eee;
    border-bottom:1px solid #ccc;
    color:#000;
    font-size:11px;
    line-height:22px;
}
#nav ul li a:hover {
    background-color:#ddd;
    color:#444;
}
#nav ul li a img, #nav ul li ul a img {
    background: url("images/bulb.png") no-repeat;
    border-width:0px;
    height:16px;
    line-height:22px;
    margin-right:5px;
    vertical-align:middle;
    width:16px;
}
#nav ul li:nth-child(odd) a img, #nav ul ul li:nth-child(odd) a img {
    background:url("images/bulb2.png") no-repeat;
}
#nav a.sub:focus {
    background:#bcbdc1;
    outline:0;
}
#nav a:focus ~ ul li ul li{
margin-top:-23px;
}
#nav a:focus ~ ul li {
    margin-top:0;

    -moz-transition:  0.4s linear;
    -ms-transition: 0.4s linear;
    -o-transition: 0.4s linears;
    -webkit-transition: 0.4s linears;
    transition: 0.4s linear;
}
#nav ul a:focus ~ ul li {
    margin-top:0;

    -moz-transition:  0.4s linear;
    -ms-transition: 0.4s linear;
    -o-transition: 0.4s linears;
    -webkit-transition: 0.4s linears;
    transition: 0.4s linear;
}
#nav a:focus + img, #nav a:active + img {
    display:block;
}
#nav a.sub:active {
    background:#bcbdc1;
    outline:0;
}
#nav a:active ~ ul li, #nav ul a:active ~ ul li {
    margin-top:0;
}

#nav ul:hover li {
    margin-top:0;
}

You can see fiddle here fiddle 你可以在这里看到小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM