1

我需要将这个纯 CSS 下拉菜单修改为下拉菜单。看到一个类似的帖子,但似乎无法修改我的。这是用于下拉菜单的 css 代码,它按预期工作。我尝试使用bottom: 100%within ul.drop li.hover, ul.drop li:hover {,但没有奏效。有什么建议么。

HTML

<body>

<ul id="nav" class="drop">
  <li><a href="#">Home</a></li>
  <li>Portfolio
    <ul>
      <li><a href="#">Horses</a>
        <ul>
          <li><a href="#">Horses 1</a>
          <li><a href="#">Horses 2</a>
          <li><a href="#">Horses 3</a>
        </ul>
      </li>
      <li><a href="#">Dogs</a></li>
      <li><a href="#">People</a></li>
      <li><a href="#">Stills</a></li>
    </ul>
  </li>
  <li><a href="#">Order</a></li>
  <li><a href="#">Contact Me</a>
     </li>
    </ul>
  </li>
</ul>

CSS

ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}

ul li {
display: block;
position: relative;
float: left;
width: 130px;
text-align: center;
}
li ul {
display: none;
}

ul li a {
    display: block;
    text-decoration: none;
    color: #ffffff;
    border-top: 0px solid #ffffff;
    padding: 0px 0px 0px 0px;
    background: transparent;
#    margin-left: 1px;
    white-space: nowrap;
}
ul li a:hover {
background: transparent;
}
li:hover ul {
    display: block;
    position: absolute;
}
li:hover li {
    float: none;
    font-size: 11px;
    width: 160px;
    text-align: left;
}
li:hover a { background: transparent; }
li:hover li a:hover {
    background: #3ba110;
}

ul.drop a {
display:block; color: #fff; font-family: Verdana; font-size: 14px; text-decoration:    none;
}


ul.drop, ul.drop li, ul.drop ul {
list-style: none; margin: 0; padding: 0; border: 1px solid #fff; background: #1302CB; color: #fff;
}
ul.drop {
position: relative; z-index: 597; float: left;
}
ul.drop li {
float: left; line-height: 1.3em; vertical-align: middle; zoom: 1; padding: 5px 10px;
}
ul.drop li.hover, ul.drop li:hover {
position: relative; z-index: 599; cursor: default; background: #3ba110;
}

ul.drop ul {
visibility: hidden; position: absolute; bottom: 100%; left: 0; z-index: 598; width: 160px; background: #cccccc; border: 1px solid #fff;
}

ul.drop ul li {
float: none;
}
ul.drop ul ul {
top: -2px; left: 100%;
}

ul.drop li:hover > ul {
visibility: visible
}
4

1 回答 1

0

I didn''t use your CSS because I am not sure what is going on without HTML. Anyways I created a basic demo of what I think you are trying to accomplish.

http://jsfiddle.net/krishollenbeck/JgWEL/45/

HTML

<div class="page">
<ul>
    <li class="navlink">
        <a href="">MENU ITEM:</a>
        <ul class="dropmenu">
            <li><a href="">Link One</a></li>
            <li><a href="">Link Two</a></li>
            <li><a href="">Link Three</a></li>
        </ul>   
    </li>    
</ul>  
</div>

CSS

.page {
    width:200px;
    height:100px;
    position:fixed;
    top:50%;
    bottom:50%;
}    
.dropmenu {
    display:none;
    border:1px solid #CCC;
    background-color:#eee;
    width:150px;
    padding:5px;
    position:absolute;
    top:-70px;
}
.navlink {
    background-color:#000;
    padding:5px;
}
.navlink > a {color:#FFF;}
.navlink:hover > .dropmenu {display:block;}
​
于 2013-01-04T20:27:44.383 回答