导航菜单顶部和底部,底部没有下降

时间:2017-06-06 14:58:58

标签: html css



<!DOCTYPE html>
<html>
<head>
<style>
ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333;
}

li {
    float: left;
}

li a, .dropbtn {
    display: inline-block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

li a:hover, .dropdown:hover .dropbtn {
    background-color: red;
}

li.dropdown {
    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);
    z-index: 1;
}

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

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

.dropdown:hover .dropdown-content {
    display: block;
}
</style>
<style>
ulf {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333;
    position: fixed;
    bottom: 0%;
    width: 100%;

}

lif {
    float: left;
		border-right: 1px solid #bbb;

}

lif a, .dropbtn {

    display: inline-block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

lif a:hover, .dropup:hover .dropbtn {

   background-color: red;
	
	

}

lif.dropup {
    display: inline-block;

}

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

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

.dropup-content a:hover {
background-color: #f1f1f1


}

.dropup:hover .dropup-content {
    display: block;
	
}
</style>
</head>
<body>

<ul>
  </li><li class="dropdown">
    <a href="javascript:void(0)" class="dropbtn">Sales</a>
    <div class="dropdown-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
  </li>
<li class="dropdown">
    <a href="javascript:void(0)" class="dropbtn">Search</a>
    <div class="dropdown-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
  </li>
  <li class="dropdown">
    <a href="javascript:void(0)" class="dropbtn">Transfers</a>
    <div class="dropdown-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
  </li>
   <li class="dropdown">
  	<a href="javascript:void(0)" class="dropbtn">Returns</a>
	    <div class="dropdown-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
	</li>
	
</ul>

<ulf>
<lif class="dropup">
    <a href="javascript:void(0)" class="dropbtn">Order</a>
    <div class="dropup-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
  </lif>
<lif class="dropup">
    <a href="javascript:void(0)" class="dropbtn">Reports</a>
    <div class="dropup-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
  </lif>
  <lif class="dropup">
    <a href="javascript:void(0)" class="dropbtn">Exports/Imports</a>
    <div class="dropup-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
  </lif>
   <lif class="dropup">
  	<a href="javascript:void(0)" class="dropbtn">Settings</a>
	    <div class="dropup-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
	</lif>
	
</ulf>

</body>
</html>
&#13;
&#13;
&#13;

顶部导航工作正常。我的意思是下拉功能正常,但底部导航不起作用。我想做一些像放弃的事情。有人可以查看代码并给我一些关于我必须做什么的指示吗?

3 个答案:

答案 0 :(得分:1)

您只需要从position: absolute;中删除.dropup-content,然后将其替换为此CSS:

  position: fixed;
  bottom: 47px;

而鲍勃是你的叔叔!

&#13;
&#13;
ulf {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #333;
  position: fixed;
  bottom: 0%;
  width: 100%;
}
lif {
  float: left;
  border-right: 1px solid #bbb;
}
lif a, .dropbtn {
  display: inline-block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}
lif a:hover, .dropup:hover .dropbtn {
  background-color: red;
}
lif.dropup {
  display: inline-block;
}
.dropup-content {
  display: none;
  position: fixed;
  bottom: 47px;
  background-color: #f9f9f9;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  z-index: 1;
}
.dropup-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  text-align: left;
}
.dropup-content a:hover {
  background-color: #f1f1f1
}
.dropup:hover .dropup-content {
  display: block;
}
&#13;
<!DOCTYPE html>
<html>
<head>
<style>
</style>
<style>
</style>
</head>
<body>
<ulf>
<lif class="dropup">
    <a href="javascript:void(0)" class="dropbtn">Order</a>
    <div class="dropup-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
  </lif>
<lif class="dropup">
    <a href="javascript:void(0)" class="dropbtn">Reports</a>
    <div class="dropup-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
  </lif>
  <lif class="dropup">
    <a href="javascript:void(0)" class="dropbtn">Exports/Imports</a>
    <div class="dropup-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
  </lif>
   <lif class="dropup">
  	<a href="javascript:void(0)" class="dropbtn">Settings</a>
	    <div class="dropup-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
	</lif>
	
</ulf>

</body>
</html>
&#13;
&#13;
&#13;

CodePen example:

答案 1 :(得分:0)

两件事:

1。)将bottom: 0添加到.dropup-content以将子菜单与其容器的底部对齐,而不是顶部。

2。)将overflow-visible添加到ulf

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #333;
}

li {
  float: left;
}

li a,
.dropbtn {
  display: inline-block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

li a:hover,
.dropdown:hover .dropbtn {
  background-color: red;
}

li.dropdown {
  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);
  z-index: 1;
}

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

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

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

ulf {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #333;
  position: fixed;
  bottom: 0%;
  width: 100%;
  overflow: visible;
}

lif {
  float: left;
  border-right: 1px solid #bbb;
}

lif a,
.dropbtn {
  display: inline-block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

lif a:hover,
.dropup:hover .dropbtn {
  background-color: red;
}

lif.dropup {
  display: inline-block;
}

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

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

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

.dropup:hover .dropup-content {
  display: block;
}
<!DOCTYPE html>
<html>

<body>

  <ul>
    </li>
    <li class="dropdown">
      <a href="javascript:void(0)" class="dropbtn">Sales</a>
      <div class="dropdown-content">
        <a href="#">Link 1</a>
        <a href="#">Link 2</a>
        <a href="#">Link 3</a>
      </div>
    </li>
    <li class="dropdown">
      <a href="javascript:void(0)" class="dropbtn">Search</a>
      <div class="dropdown-content">
        <a href="#">Link 1</a>
        <a href="#">Link 2</a>
        <a href="#">Link 3</a>
      </div>
    </li>
    <li class="dropdown">
      <a href="javascript:void(0)" class="dropbtn">Transfers</a>
      <div class="dropdown-content">
        <a href="#">Link 1</a>
        <a href="#">Link 2</a>
        <a href="#">Link 3</a>
      </div>
    </li>
    <li class="dropdown">
      <a href="javascript:void(0)" class="dropbtn">Returns</a>
      <div class="dropdown-content">
        <a href="#">Link 1</a>
        <a href="#">Link 2</a>
        <a href="#">Link 3</a>
      </div>
    </li>

  </ul>

  <ulf>
    <lif class="dropup">
      <a href="javascript:void(0)" class="dropbtn">Order</a>
      <div class="dropup-content">
        <a href="#">Link 1</a>
        <a href="#">Link 2</a>
        <a href="#">Link 3</a>
      </div>
    </lif>
    <lif class="dropup">
      <a href="javascript:void(0)" class="dropbtn">Reports</a>
      <div class="dropup-content">
        <a href="#">Link 1</a>
        <a href="#">Link 2</a>
        <a href="#">Link 3</a>
      </div>
    </lif>
    <lif class="dropup">
      <a href="javascript:void(0)" class="dropbtn">Exports/Imports</a>
      <div class="dropup-content">
        <a href="#">Link 1</a>
        <a href="#">Link 2</a>
        <a href="#">Link 3</a>
      </div>
    </lif>
    <lif class="dropup">
      <a href="javascript:void(0)" class="dropbtn">Settings</a>
      <div class="dropup-content">
        <a href="#">Link 1</a>
        <a href="#">Link 2</a>
        <a href="#">Link 3</a>
      </div>
    </lif>

  </ulf>

</body>

</html>

答案 2 :(得分:0)

删除隐藏在ulf中的溢出,添加底部:46px到.dropup-content以使其高于底部导航。

&#13;
&#13;
<!DOCTYPE html>
<html>
<head>
<style>
ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333;
}

li {
    float: left;
}

li a, .dropbtn {
    display: inline-block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

li a:hover, .dropdown:hover .dropbtn {
    background-color: red;
}

li.dropdown {
    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);
    z-index: 1;
}

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

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

.dropdown:hover .dropdown-content {
    display: block;
}
</style>
<style>
ulf {
    list-style-type: none;
    margin: 0;
    padding: 0;
    background-color: #333;
    position: fixed;
    bottom: 0%;
    width: 100%;

}

lif {
    float: left;
		border-right: 1px solid #bbb;

}

lif a, .dropbtn {

    display: inline-block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

lif a:hover, .dropup:hover .dropbtn {

   background-color: red;
	
	

}

lif.dropup {
    display: inline-block;
}

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

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

.dropup-content a:hover {
background-color: #f1f1f1


}

.dropup:hover .dropup-content {
    display: block;
	
}
</style>
</head>
<body>

<ul>
  <li class="dropdown">
    <a href="javascript:void(0)" class="dropbtn">Sales</a>
    <div class="dropdown-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
  </li>
<li class="dropdown">
    <a href="javascript:void(0)" class="dropbtn">Search</a>
    <div class="dropdown-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
  </li>
  <li class="dropdown">
    <a href="javascript:void(0)" class="dropbtn">Transfers</a>
    <div class="dropdown-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
  </li>
   <li class="dropdown">
  	<a href="javascript:void(0)" class="dropbtn">Returns</a>
	    <div class="dropdown-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
	</li>
	
</ul>

<ulf>
<lif class="dropup">
    <a href="javascript:void(0)" class="dropbtn">Order</a>
    <div class="dropup-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
  </lif>
<lif class="dropup">
    <a href="javascript:void(0)" class="dropbtn">Reports</a>
    <div class="dropup-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
  </lif>
  <lif class="dropup">
    <a href="javascript:void(0)" class="dropbtn">Exports/Imports</a>
    <div class="dropup-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
  </lif>
   <lif class="dropup">
  	<a href="javascript:void(0)" class="dropbtn">Settings</a>
	    <div class="dropup-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>
    </div>
	</lif>
	
</ulf>

</body>
</html>
&#13;
&#13;
&#13;