【问题标题】:Bootstrap Dropdown on Hover Removing Styles悬停删除样式的引导下拉菜单
【发布时间】:2015-07-29 13:13:10
【问题描述】:

目前我正在尝试使我的引导下拉菜单仅在悬停而不是单击时发生。

我有一个 100% 宽度的下拉菜单,所有样式都已通过点击方法进行设置,但是当我更改 CSS 以使下拉菜单出现在悬停时,它似乎会删除样式或覆盖它们?

任何帮助都会很棒。

HTML

    <li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><i class="ion-navicon icon"></i><span class="caret"></span></a>
      <ul class="dropdown-menu">
        <li>
            <a href="#">Another action</a>
            <a href="#">Another action</a>
            <a href="#">Another action</a>
            <a href="#">Another action</a>
        </li>
        <li><a href="#">Something else here</a></li>
        <li role="separator" class="divider"></li>
        <li><a href="#">Separated link</a></li>
        <li role="separator" class="divider"></li>
        <li><a href="#">One more separated link</a></li>
      </ul>
    </li>

我的 CSS

.nav > li.dropdown.open { position: static; }
.nav > li.dropdown.open .dropdown-menu 
{
    display:table; 
    width: 100%; 
    text-align: center; 
    left:0; 
    right:0; 
    margin-top:-1px; 
    box-shadow: none; 
    border:none;
    background:#252525;
}

.dropdown-menu>li { display: table-cell; }

但是当我添加下面的代码时,它会立即变回原来的样式?

.dropdown:hover .dropdown-menu {
    display: block;
    margin-top: 0; // remove the gap so it doesn't close
 }

如果有任何区别,后端是 Wordpress。

谢谢

【问题讨论】:

    标签: html css wordpress twitter-bootstrap


    【解决方案1】:

    在你的 css 文件中试试这个:

    ul.nav li.dropdown:hover > ul.dropdown-menu {
        display: block;    
    }
    

    【讨论】:

    • 这没有提供问题的答案。要批评或要求作者澄清,请在其帖子下方发表评论。
    • 不幸的是,它仍在删除样式。很奇怪
    • @HenriqueBarcelos 我没有批评或要求作者澄清。这就是我所做的和工作的。
    【解决方案2】:

    解决方案

    @media (min-width: 767px) {
      .navbar-default .tablemenu {
        border-radius: 0px;
        background: #E7E7E7;
        padding: 0;
        margin: 0;
      }
      .navbar-default .tablemenu > li > a {
        padding: 5px 0;
        margin: 0;
        line-height: 20px;
        color: #777;
      }
      .navbar-default ul.nav li:hover > ul.dropdown-menu,
      .navbar-default .nav > li.dropdown.open .dropdown-menu {
        display: table;
        width: 100%;
        text-align: center;
        box-shadow: none;
        border: none;
      }
      .navbar-default .tablemenu-large {
        position: static !important;
      }
      .navbar-default .dropdown-menu > li {
        display: table-cell;
      }
    }
    @media (max-width: 768px) {
      .tablemenu > li > ul > li {
        list-style: none;
      }
      .tablemenu > li > ul > li > a {
        display: block;
        padding: 3px 5px;
      }
      .tablemenu > li > a:hover,
      .tablemenu > li > a:focus {
        text-decoration: none;
        background-color: #E7E7E7 !important;
      }
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
    <div class="navbar navbar-default">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="icon-bar"></span>  <span class="icon-bar"></span>  <span class="icon-bar"></span> 
          </button>
          <a class="navbar-brand" href="#">Brand</a> 
        </div>
        <div class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li class="dropdown tablemenu-large ">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"> <span class="caret"></span>
              </a>
              <ul class="dropdown-menu tablemenu">
                <li> <a href="#">Another action 1</a>  <a href="#">Another action 2</a>  <a href="#">Another action 3</a>  <a href="#">Another action 4</a> 
                </li>
                <li><a href="#">Something else here A</a> 
                </li>
                <li role="separator" class="divider"></li>
                <li><a href="#">Separated link B</a> 
                </li>
                <li role="separator" class="divider"></li>
                <li><a href="#">One more separated link C</a> 
                </li>
              </ul>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <div class="container">
      <div class="well well-lg">Bootstrap 3</div>
      <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up
        one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum
        et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section
        1.10.32. Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia,</p>
      <p>looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus
        Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line
        in section 1.10.32. Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College
        in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source.</p>
      <p>Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line
        of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.
        Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable
        source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first
        line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>
    </div>

    【讨论】:

    • 这似乎是一种相当混乱的处理方式。
    猜你喜欢
    • 2013-04-19
    • 2012-08-10
    • 2019-04-19
    • 2016-04-02
    • 2013-10-10
    • 2014-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多