慢下拉菜单CSS

时间:2016-11-02 13:27:58

标签: html css

在网站上找到了很多建议。我试着让它工作,但是不同类型的下拉菜单。我试着慢慢下降css下拉菜单。 这是html -

大多数帮助都是以列表框的导航栏的形式出现,但我更喜欢这种方法,它位置很好。



.dropbtn {
  background-color: #4CAF50;
  transition: 0.3s;
  color: white;
  padding: 16px;
  padding-right: 32px;
  font-size: 16px;
  border: none;
  cursor: crosshair;
  border-radius: 2px;
}
/* Dropdown Content (Hidden by Default) */

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

.dropdown-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}
/* Change color of dropdown links on hover */

.dropdown-content a:hover {
  background-color: #f1f1f1;
  color: #000000;
}
/* Show the dropdown menu on hover */

.dropdown:hover .dropdown-content {
  display: inline;
}
/* Change the background color of the dropdown button when the dropdown content is shown */

.dropdown:hover .dropbtn {
  background-color: #3e8e41;
  color: #000000;
}
.dropdown1 {
  position: fixed;
  top: 150px;
  left: 50px;
}
.dropdown2 {
  position: fixed;
  top: 150px;
  left: 220px;
}
.dropdown3 {
  position: fixed;
  top: 150px;
  left: 615px;
}
.dropdown4 {
  position: fixed;
  top: 150px;
  left: 1003px;
}
.pageheading {
  font-family: verdana;
  font-size: 85%;
  position: absolute;
  left: 50px;
  top: 210px;
  background-color: #4CAF50;
  border-radius: 6px;
}
.pageparagraph {
  font-family: verdana;
  text-align: justify;
  position: absolute;
  left: 50px;
  top: 290px;
  right: 685px;
  background-color: #4CAF50;
  border-radius: 6px;
}
.logo {
  font-family: verdana;
  font-size: 150%;
  color: white;
  position: fixed;
  top: 10px;
  left: 50px;
  background-color: #4CAF50;
  border-radius: 6px;
}
body {
  background-image: url("ForestBackground.jpg");
  background-repeat: no-repeat;
}
.arrow1 {
  position: fixed;
  top: 166px;
  left: 185;
  transform: rotate(0deg);
  transition: 0.3s;
}
.arrow2 {
  position: fixed;
  top: 166px;
  left: 580;
  transform: rotate(0deg);
  transition: 0.3s;
}
.arrow3 {
  position: fixed;
  top: 166px;
  left: 970;
  transform: rotate(0deg);
  transition: 0.3s;
}
.arrow4 {
  position: fixed;
  top: 166px;
  left: 1130;
  transform: rotate(0deg);
  transition: 0.3s;
}
.dropdown:hover .arrow1 {
  transform: rotate(90deg);
  transition: 0.3s;
}
.dropdown:hover .arrow2 {
  transform: rotate(90deg);
  transition: 0.3s;
}
.dropdown:hover .arrow3 {
  transform: rotate(90deg);
  transition: 0.3s;
}
.dropdown:hover .arrow4 {
  transform: rotate(90deg);
  transition: 0.3s;
}

<div class="dropdown">
  <div class="dropdown1">
    <button class="dropbtn">Climate Change
      <div class="arrow1">&#10162;</div>
    </button>
    <div class="dropdown-content">
      <a href="https://thepotatoshop.com/shop/mash/highland-burgundy-red-1kg/">Greenhouse Gases</a>
      <a href="https://thepotatoshop.com/shop/mash/arran-victory-1kg/">Carbon Dioxide</a>
      <a href="https://thepotatoshop.com/shop/mash/desiree-1kg/">Methane</a>
      <a href="https://thepotatoshop.com/shop/salad/belle-de-fontenay-1kg/">Water Vapour</a>
      <a href="https://thepotatoshop.com/shop/salad/belle-de-fontenay-1kg/">NF3</a>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

我想要一个下降的,向下滑动的菜单,而不是任何建议朋友的淡出?

编辑 - 只需编辑此内容即可感谢所有帮助!主要是为了让我的帐户能够再次提问,我不知道为什么我被禁止了。请帮忙。爱你们所有人。

2 个答案:

答案 0 :(得分:1)

https://jsfiddle.net/btLjk40x/2/〜检查这个小提琴

.dropdown-content {
    overflow: hidden:
    height: 0;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    transition: all 1s ease-in;
}
.dropdown:hover .dropdown-content {
    height: 200px; // sample height
}

答案 1 :(得分:0)

如果您想模拟“向下滑动”效果,可以为子菜单元素添加额外的包装,并使用translate,如下所示:

  

警告:您正在使用大量固定位置,这些位置会导致您稍后因响应布局而出现问题,而某些位置则不必像箭头那样

.dropbtn {
  background-color: #4CAF50;
  transition: 0.3s;
  color: white;
  padding: 16px;
  padding-right: 32px;
  font-size: 16px;
  border: none;
  cursor: crosshair;
  border-radius: 2px;
}
.dropdown-content {
  position: absolute;
  width:100%;
  overflow:hidden;
}
.dropdown-content > div {
  background-color: #f9f9f9;
  transform:translateY(-100%);
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  transition:transform 1s;
}
.dropdown-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}
.dropdown-content a:hover {
  background-color: #f1f1f1;
  color: #000000;
}
.dropdown:hover .dropdown-content > div {
  transform:translateY(0);
}
.dropdown:hover .dropbtn {
  background-color: #3e8e41;
  color: #000000;
  transition: 0.3s;
}
.dropdown1 {
  position: fixed;
  top: 150px;
  left: 50px;
}
.dropdown2 {
  position: fixed;
  top: 150px;
  left: 220px;
}
.dropdown3 {
  position: fixed;
  top: 150px;
  left: 615px;
}
.dropdown4 {
  position: fixed;
  top: 150px;
  left: 1003px;
}
.pageheading {
  font-family: verdana;
  font-size: 85%;
  position: absolute;
  left: 50px;
  top: 210px;
  background-color: #4CAF50;
  border-radius: 6px;
}
.pageparagraph {
  font-family: verdana;
  text-align: justify;
  position: absolute;
  left: 50px;
  top: 290px;
  right: 685px;
  background-color: #4CAF50;
  border-radius: 6px;
}
.logo {
  font-family: verdana;
  font-size: 150%;
  color: white;
  position: fixed;
  top: 10px;
  left: 50px;
  background-color: #4CAF50;
  border-radius: 6px;
}
body {
  background-image: url("ForestBackground.jpg");
  background-repeat: no-repeat;
}
.arrow1 {
  position: fixed;
  top: 166px;
  left: 185;
  transform: rotate(0deg);
  transition: 0.3s;
}
.arrow2 {
  position: fixed;
  top: 166px;
  left: 580;
  transform: rotate(0deg);
  transition: 0.3s;
}
.arrow3 {
  position: fixed;
  top: 166px;
  left: 970;
  transform: rotate(0deg);
  transition: 0.3s;
}
.arrow4 {
  position: fixed;
  top: 166px;
  left: 1130;
  transform: rotate(0deg);
  transition: 0.3s;
}
.dropdown:hover .arrow1 {
  transform: rotate(90deg);
  transition: 0.3s;
}
.dropdown:hover .arrow2 {
  transform: rotate(90deg);
  transition: 0.3s;
}
.dropdown:hover .arrow3 {
  transform: rotate(90deg);
  transition: 0.3s;
}
.dropdown:hover .arrow4 {
  transform: rotate(90deg);
  transition: 0.3s;
}
<div class="dropdown">
  <div class="dropdown1">
    <button class="dropbtn">Climate Change
      <div class="arrow1">&#10162;</div>
    </button>
    <div class="dropdown-content">
      <div>
        <a href="https://thepotatoshop.com/shop/mash/highland-burgundy-red-1kg/">Greenhouse Gases</a>
        <a href="https://thepotatoshop.com/shop/mash/arran-victory-1kg/">Carbon Dioxide</a>
        <a href="https://thepotatoshop.com/shop/mash/desiree-1kg/">Methane</a>
        <a href="https://thepotatoshop.com/shop/salad/belle-de-fontenay-1kg/">Water Vapour</a>
        <a href="https://thepotatoshop.com/shop/salad/belle-de-fontenay-1kg/">NF3</a>
      </div>
    </div>
  </div>
</div>