亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法創建垂直菜單

無法創建垂直菜單

萬千封印 2023-12-04 15:04:56
我正在嘗試創建一個垂直菜單,但最終結果如下所示:這是我的代碼:$("#example-one").append("<li id='magic-line'></li>");/* Cache it */var $magicLine = $("#magic-line");$magicLine  .width($(".current_page_item").width())  .css("left", $(".current_page_item a").position().left)  .data("origLeft", $magicLine.position().left)  .data("origWidth", $magicLine.width());$("#example-one li")  .find("a")  .hover(    function() {      $el = $(this);      leftPos = $el.position().left;      newWidth = $el.parent().width();      $magicLine.stop().animate({        left: leftPos,        width: newWidth      });    },    function() {      $magicLine.stop().animate({        left: $magicLine.data("origLeft"),        width: $magicLine.data("origWidth")      });    }  );.nav-wrap {  margin: 50px auto;  background-color: rgba(0, 0, 0, 0.6);  border-top: 2px solid white;  border-bottom: 2px solid white;}/* Clearfix */.group:after {  visibility: hidden;  display: block;  content: "";  clear: both;  height: 0;}*:first-child+html .group {  zoom: 1;}/* IE7 *//* Example One */#example-one {  margin: 0 auto;  list-style: none;  position: relative;  width: 200px;}#example-one li {  display: inline-block;}#example-one a {  color: #bbb;  font-size: 14px;  float: left;  padding: 6px 10px 4px 10px;  text-decoration: none;  text-transform: uppercase;}#example-one a:hover {  color: white;}#magic-line {  position: absolute;  bottom: -2px;  left: 0;  width: 100px;  height: 2px;  background: #fe4902;}.current_page_item a {  color: white !important;}.ie6 #example-one li,.ie7 #example-one li {  display: inline;}.ie6 #magic-line {  bottom: -3px;}本質上我希望將所有項目都作為垂直菜單,如下所示: https: //www.w3schools.com/howto/howto_css_vertical_menu.asp我嘗試添加特定寬度,但得到相同的結果我怎樣才能做到這一點?
查看完整描述

2 回答

?
慕村9548890

TA貢獻1884條經驗 獲得超4個贊

請將您的 CSS 代碼替換為這些行。


 .nav-wrap {

      margin: 50px auto;

      background-color: rgba(0, 0, 0, 0.6);

      border-top: 2px solid white;

      border-bottom: 2px solid white;

    }

    

    /* Clearfix */

    .group:after {

      visibility: hidden;

      display: block;

      content: "";

      clear: both;

      height: 0;

    }

    

    *:first-child+html .group {

      zoom: 1;

    }

    

    /* IE7 */

    

    /* Example One */

    #example-one {

        list-style: none;

        position: relative;

        display: grid;

        max-width: 200px;

        background: #F1F1F1;

        padding: 0px;

    }

    

    #example-one li {

      display: inline-block;

    }

    

    #example-one a {

        color: #000;

        font-family: sans-serif;

        font-size: 14px;

        width: 100%;

        float: left;

        padding: 11px;

        text-decoration: none;

        text-transform: capitalize;

    }

    

    #example-one a:hover {

        color: #818181;

    }

    

    #magic-line {

      position: absolute;

      bottom: -2px;

      left: 0;

      width: 100px;

      height: 2px;

      background: #fe4902;

    }

    .current_page_item {

        background: #4CAF50;

    }

    .current_page_item a { 

      color:white;

    }

<div class="menu">

  <ul class="group" id="example-one">

    <li class="current_page_item" data-target="home" data-posmenu="-35px"><a href="index.php#home">hello</a></li>

    <li class="" data-target="about"><a href="index.php#about">About</a></li>

    <li class="" data-target="product"><a href="index.php#product">PRODUCTS</a></li>

    <li class="" data-target="news"><a href="index.php#news">News</a></li>

    <li class="" data-target="contact"><a href="index.php#contact">Contact</a></li>

    <li class="" data-target="policy_privacy"><a href="<?php echo ABSOLUTE_PATH.BASE_PAGE; ?>?<?php echo PAGE_PARAM_KEY; ?>=privacy_policy">Privacy</a></li>

  </ul>

</div>


查看完整回答
反對 回復 2023-12-04
?
ITMISS

TA貢獻1871條經驗 獲得超8個贊

您正在使用float和display: inline-block。只需刪除這些屬性即可。


.nav-wrap {

  margin: 50px auto;

  background-color: rgba(0, 0, 0, 0.6);

  border-top: 2px solid white;

  border-bottom: 2px solid white;

}



/* Clearfix */


.group:after {

  visibility: hidden;

  display: block;

  content: "";

  clear: both;

  height: 0;

}


*:first-child+html .group {

  zoom: 1;

}



/* IE7 */



/* Example One */


#example-one {

  margin: 0 auto;

  list-style: none;

  position: relative;

  width: 200px;

}


#example-one a {

  color: #bbb;

  font-size: 14px;

  padding: 6px 10px 4px 10px;

  text-decoration: none;

  text-transform: uppercase;

}


#example-one a:hover {

  color: white;

}


#magic-line {

  position: absolute;

  bottom: -2px;

  left: 0;

  width: 100px;

  height: 2px;

  background: #fe4902;

}


.current_page_item a {

  color: white !important;

}


.ie6 #magic-line {

  bottom: -3px;

}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="menu">

  <ul class="group" id="example-one">

    <li class="current_page_item" data-target="home" data-posmenu="-35px"><a href="index.php#home">hello</a></li>

    <li class="" data-target="about"><a href="index.php#about">About</a></li>

    <li class="" data-target="product"><a href="index.php#product">PRODUCTS</a></li>

    <li class="" data-target="news"><a href="index.php#news">News</a></li>

    <li class="" data-target="contact"><a href="index.php#contact">Contact</a></li>

    <li class="" data-target="policy_privacy"><a href="<?php echo ABSOLUTE_PATH.BASE_PAGE; ?>?<?php echo PAGE_PARAM_KEY; ?>=privacy_policy">Privacy</a></li>

  </ul>

</div>


查看完整回答
反對 回復 2023-12-04
  • 2 回答
  • 0 關注
  • 147 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號