有什么方法可以在导航列表项上添加“悬停时的下拉菜单”吗?

我有一个导航,我想在我的两个导航列表项(左侧的前两个)中添加一个下拉菜单(悬停时)。最好的方法是什么?我尝试了Google的一些解决方案,但没有一个真正对我有用,这只是弄乱了我的导航。


这是我的导航:(展开至完整页面以查看导航功能)


ul li {

  list-style: none;

}


html {

  font-family: "Roboto", serif;

}


.navigation {

  position: fixed;

  width: 100%;

  text-align: center;

  font-size: 14px;

  font-size: 0.875rem;

  line-height: 1.5em;

  height: 180px;

  font-family: "Roboto", serif;

  transition: all 0.5s ease;

  display: flex;

  justify-content: center;

  align-items: center;

  z-index: 99999;

  background-color: rgba(175, 213, 123, 0.70);

}


.navigation ul {

  display: flex;

  flex-direction: row;

  margin: 0;

  padding: 0;

  z-index: 1;

}


.navigation ul li {

  float: left;

  padding: 0 20px;

  text-decoration: none;

  text-transform: uppercase;

  color: #222222;

  margin: -12px 0;

  letter-spacing: 0.200em;

  transition: all 0.5s ease;

}


.navigation ul li:hover {

  color: #ffa947;

  cursor: pointer;

}


@media (min-width: 0) and (max-width: 770px) {

  .navigation ul li {

    margin: 17px 0;

  }

}


.navigation ul li.reg {

  font-size: 10px;

  font-size: 0.625rem;

}


@media (min-width: 0) and (max-width: 770px) {

  .navigation ul li.reg {

    display: none;

  }

}


.navigation ul li.title {

  font-size: 24px;

  font-size: 1.5rem;

}


.navigation h1 {

  font-size: 24px;

  font-size: 1.5rem;

  color: #222222;

  font-weight: 300;

  z-index: 1;

  margin: 0;

  padding: 0;

  letter-spacing: 10px;

}


@media (min-width: 0) and (max-width: 770px) {

  .navigation {

    flex-direction: column;

    height: auto;

  }

}


.navigation.sticky {

  height: 55px;

  background-color: rgba(175, 213, 123, 1);

}


.navigation.sticky::after {

  opacity: 1;

  filter: alpha(opacity=100);

}


.navigation.sticky ul li {

  margin: 0;

}


@media (min-width: 0) and (max-width: 770px) {

  .navigation.sticky {

    height: auto;

  }

  .navigation.sticky .title {

    margin: 17px 0;

  }

}


.navigation .hidden {

  visibility: hidden;

  height: 0;

  display: none;

}



慕姐8265434
浏览 172回答 1
1回答

阿晨1998

ul li {&nbsp; list-style: none;}html {&nbsp; font-family: "Roboto", serif;}.navigation {&nbsp; position: fixed;&nbsp; width: 100%;&nbsp; text-align: center;&nbsp; font-size: 14px;&nbsp; font-size: 0.875rem;&nbsp; line-height: 1.5em;&nbsp; height: 180px;&nbsp; font-family: "Roboto", serif;&nbsp; transition: all 0.5s ease;&nbsp; display: flex;&nbsp; justify-content: center;&nbsp; align-items: center;&nbsp; z-index: 99999;&nbsp; background-color: rgba(175, 213, 123, 0.70);}.navigation ul {&nbsp; display: flex;&nbsp; flex-direction: row;&nbsp; margin: 0;&nbsp; padding: 0;&nbsp; z-index: 1;}.navigation ul li {&nbsp; float: left;&nbsp; padding: 0 20px;&nbsp; text-decoration: none;&nbsp; text-transform: uppercase;&nbsp; color: #222222;&nbsp; margin: -12px 0;&nbsp; letter-spacing: 0.200em;&nbsp; transition: all 0.5s ease;&nbsp; position:relative;}.navigation ul li a{&nbsp; font-size: 0.625rem;&nbsp; text-decoration: none;&nbsp; &nbsp;color: #222222;}.navigation ul li a:hover{&nbsp; color: #ffa947;}.navigation ul li .submenu{&nbsp; display:none;&nbsp; position: absolute;&nbsp; top:15px;&nbsp; left:0;&nbsp; width: 200px;&nbsp; background: #FFF;&nbsp; border: 1px #e8e8e8 solid;&nbsp;&nbsp;}.navigation ul li:hover .submenu{&nbsp; display: block;}.navigation ul li .submenu li{&nbsp; display: inline-block;&nbsp; width: calc(100% - 20px);&nbsp; margin: 0;&nbsp; padding: 5px 10px;&nbsp; list-style: none;&nbsp; border-bottom: 1px #e8e8e8 solid;}.navigation ul li .submenu li a{&nbsp; color: #ffa947;}.navigation ul li:hover {&nbsp; color: #ffa947;&nbsp; cursor: pointer;}@media (min-width: 0) and (max-width: 770px) {&nbsp; .navigation ul li {&nbsp; &nbsp; margin: 17px 0;&nbsp; }}.navigation ul li.reg {&nbsp; font-size: 10px;&nbsp; font-size: 0.625rem;}@media (min-width: 0) and (max-width: 770px) {&nbsp; .navigation ul li.reg {&nbsp; &nbsp; display: none;&nbsp; }}.navigation ul li.title a{&nbsp; font-size: 24px;&nbsp; font-size: 1.5rem;}.navigation h1 {&nbsp; font-size: 24px;&nbsp; font-size: 1.5rem;&nbsp; color: #222222;&nbsp; font-weight: 300;&nbsp; z-index: 1;&nbsp; margin: 0;&nbsp; padding: 0;&nbsp; letter-spacing: 10px;}@media (min-width: 0) and (max-width: 770px) {&nbsp; .navigation {&nbsp; &nbsp; flex-direction: column;&nbsp; &nbsp; height: auto;&nbsp; }}.navigation.sticky {&nbsp; height: 55px;&nbsp; background-color: rgba(175, 213, 123, 1);}.navigation.sticky::after {&nbsp; opacity: 1;&nbsp; filter: alpha(opacity=100);}.navigation.sticky ul li {&nbsp; margin: 0;}@media (min-width: 0) and (max-width: 770px) {&nbsp; .navigation.sticky {&nbsp; &nbsp; height: auto;&nbsp; }&nbsp; .navigation.sticky .title {&nbsp; &nbsp; margin: 17px 0;&nbsp; }}.navigation .hidden {&nbsp; visibility: hidden;&nbsp; height: 0;&nbsp; display: none;}@media (min-width: 0) and (max-width: 770px) {&nbsp; .navigation .hidden {&nbsp; &nbsp; display: flex;&nbsp; &nbsp; flex-direction: column;&nbsp; &nbsp; margin: 0;&nbsp; &nbsp; padding: 0;&nbsp; &nbsp; float: left;&nbsp; }&nbsp; .navigation .hidden li {&nbsp; &nbsp; margin: 0;&nbsp; &nbsp; padding: 10px 0;&nbsp; &nbsp; transition: all 0s;&nbsp; }}.navigation .hidth {&nbsp; display: none;}.navigation .switch .hidth {&nbsp; display: block;}.navigation .switch .unhid {&nbsp; display: none;}.navigation .hidden.showmenu {&nbsp; visibility: hidden;&nbsp; height: 0;&nbsp; display: none;}@media (min-width: 0) and (max-width: 770px) {&nbsp; .navigation .hidden.showmenu {&nbsp; &nbsp; visibility: visible;&nbsp; &nbsp; height: auto;&nbsp; &nbsp; display: block;&nbsp; }&nbsp; .navigation .hidden.showmenu li {&nbsp; &nbsp; width: 100%;&nbsp; &nbsp; float: left;&nbsp; &nbsp; transition: all 0s;&nbsp; }&nbsp; .navigation .hidden.showmenu li:last-child {&nbsp; &nbsp; padding-bottom: 30px;&nbsp; }}.navigation .bar {&nbsp; display: none;&nbsp; margin: 17px 0;&nbsp; font-size: 21px;}@media (min-width: 0) and (max-width: 770px) {&nbsp; .navigation .bar {&nbsp; &nbsp; display: block;&nbsp; }}.navigation .bar:hover {&nbsp; cursor: pointer;}<nav class="navigation">&nbsp; <ul>&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; <li class="reg goHome"> <a href="#">Kleingartenverein</a>&nbsp; &nbsp; &nbsp; <ul class="submenu">&nbsp; &nbsp; &nbsp; &nbsp; <li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="#">Demo Link</a>&nbsp; &nbsp; &nbsp; &nbsp; </li>&nbsp; &nbsp; &nbsp; &nbsp; <li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="#">Demo Link</a>&nbsp; &nbsp; &nbsp; &nbsp; </li>&nbsp; &nbsp; &nbsp; &nbsp; <li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="#">Demo Link</a>&nbsp; &nbsp; &nbsp; &nbsp; </li>&nbsp; &nbsp; &nbsp; </ul>&nbsp; &nbsp; &nbsp; </li>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; <li class="reg goug"><a href="#">UrbanGardening </a>&nbsp; &nbsp; &nbsp; &nbsp; <ul class="submenu">&nbsp; &nbsp; &nbsp; &nbsp; <li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="#">Demo Link</a>&nbsp; &nbsp; &nbsp; &nbsp; </li>&nbsp; &nbsp; &nbsp; &nbsp; <li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="#">Demo Link</a>&nbsp; &nbsp; &nbsp; &nbsp; </li>&nbsp; &nbsp; &nbsp; &nbsp; <li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="#">Demo Link</a>&nbsp; &nbsp; &nbsp; &nbsp; </li>&nbsp; &nbsp; &nbsp; </ul>&nbsp; &nbsp; &nbsp; </li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; <li class="title gotop"><a href="#">GARDEN7</a></li>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; <li class="reg goGalerie"><a href="#">Galerie</a></li>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; <li class="reg goKontakt"><a href="#">Kontakt</a></li>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span class="bar">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <i class="fa fa-bars unhid" aria-hidden="true"></i>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <i class="fa fa-times hidth" aria-hidden="true"></i>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>&nbsp; </ul>&nbsp; <ul class="hidden">&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; <li class="goHomemob"><a href="#">Kleingartenverein</a></li>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; <li class="goKleingartenvereinmob"><a href="#">Urban Gardening </a></li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; <li class="goGaleriemob"><a href="#">Galerie</a></li>&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; <li class="goKontaktmob"><a href="#">Kontakt</a></li>&nbsp; &nbsp;&nbsp;&nbsp; </ul></nav>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript