怎么做下拉列表

时间:2016-11-16 11:06:38

标签: html css

我想使用html&amp ;;进入我的网站横向下拉列表css,我不能这样做,我在列表和桌面上尝试它,但它没有工作。 有人可以给我这个代码或者教我如何做这个吗?

这是我的代码:



.dropbtn {
  background-color: #4CAF50; 
  color: white;
  padding: 16px;
  font-size: 16px;
  border: none;
  cursor: pointer;
}

.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}

.dropdown-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}

.dropdown-content a:hover {
  background-color: #f1f1f1
}

.dropdown:hover .dropdown-content {
  display: block;
}

.dropdown:hover .dropbtn {
  background-color: #3e8e41;
}

<ul>
  <li class="lo"  style="float:right"><a href="">try</a></li>
  <li class="lo"><a href="">
    <div class="dropdown">
      <button class="dropbtn">Dropdown</button>
      <div class="dropdown-content">
        <a href="#">Link 1</a>
        <a href="#">Link 2</a>
        <a href="#">Link 3</a>
      </div>
    </div></a></li>
  <li class="lo"><a href="">try</a></li>
  <li class="lo"><a href="">try</a></li>
  <li class="lo"><a href="">try</a></li>
</ul>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

这是你想要达到的目标吗? http://codepen.io/anon/pen/WoGXeM

  <!DOCTYPE html>
      <head>
       <title>dropdown list</title>
    <style>
.dropbtn {
    background-color: #4CAF50;
    color: white;
    padding: 16px;
    font-size: 16px;
    border: none;
    cursor: pointer;
}

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    top: 50px;
    left: 0;
  white-space: nowrap;
    height: auto;
}

.dropdown-content a {
    color: black;
    padding: 16px;
    text-decoration: none;
    display: block;
}

.dropdown-content .column {
    display: inline-block;
}

.dropdown-content a:hover {background-color: #f1f1f1}

.dropdown:hover .dropdown-content {
    display: block;
}

.dropdown:hover .dropbtn {
    background-color: #3e8e41;
}
    </style>
      </head>
      <body>
      <ul>
      <li class="lo"  style="float:right"><a href="">try</a></li>
      <li class="lo">
      <div class="dropdown">
  <button class="dropbtn">Dropdown</button>
  <div class="dropdown-content">
    <div class="column">
      <a href="#"><strong>Link 1 Heading</strong></a>
      <a href="#">Link 1</a>
      <a href="#">Link 1</a>
     </div>
    <div class="column">
      <a href="#"><strong>Link 2 Heading</strong></a>
      <a href="#">Link 2</a>
      <a href="#">Link 2</a>
     </div>
    <div class="column">
      <a href="#"><strong>Link 3 Heading</strong></a>
      <a href="#">Link 3</a>
      <a href="#">Link 3</a>
     </div>
  </div>
</div></li>
      <li class="lo"><a href="">try</a></li>
      <li class="lo"><a href="">try</a></li>
      <li class="lo"><a href="">try</a></li>
    </ul>
      </body>
    </html>