简体   繁体   English

设置引导下拉菜单的样式

[英]styling a bootstrap dropdown menu

I'm not sure why my CSS is not hitting my HTML and styling it correctly. 我不知道为什么我的CSS没有打到HTML并正确设置样式。

HTML: HTML:

<li class="dropdown">
    <a href="#" data-toggle="dropdown" class="dropdown-toggle">Page 2 <b class="caret"></b></a>
    <ul class="dropdown-menu">
        <li><a href="#">Page 2.0.0 </a></li>
        <li class="divider"></li>
        <li><a href="#">Page 2.0.1 </a></li>
        <li class="divider"></li>
        <li><a href="#">Page 2.0.2 </a></li>
    </ul>
</li>

CSS: CSS:

.dropdown-menu li:hover{
    background-color: green;
}

The class dropdown-menu should be hit and then when you hover over the li 's inside it. 应该点击类dropdown-menu ,然后将鼠标悬停在li的内部。 I have tried adding an id as dropdown menu and changing the CSS to #dropdown-menu but it made no difference. 我尝试过添加一个ID作为下拉菜单,并将CSS更改为#dropdown-menu但这没有什么区别。
Also, is there an easy way to find out exactly how to hit the appropriate element as I find this is a frequent problem? 另外,是否有一种简单的方法可以准确地找到如何击中适当的元素,因为我发现这是一个常见的问题?

Ok here we go, 好,我们走了,

here is the working solution of your problem, 这是您问题的有效解决方案,

.dropdown-menu > li > a:focus,
.dropdown-menu > li > a:hover {
    clear: both;
   background-color: green !important;
   background-image:none !important; 
    display: block;
    font-weight: 400;
    line-height: 1.42857;
    padding: 3px 20px;
    white-space: nowrap;
    color: black !important;
}

i have just edited your code http://jsfiddle.net/bf1cyptm/1/ 我刚刚编辑了您的代码http://jsfiddle.net/bf1cyptm/1/

:) :)

Try adding !important in CSS like: 尝试在CSS中添加!important ,例如:

.dropdown-menu li a:hover{
    background-color:green !important;
}

If it does not work it could possibly be some other CSS code that is not letting it happen. 如果不起作用,则可能是其他一些CSS代码无法实现。 So the solution to it is to do an inspect element and see which element is affecting it. 因此,解决方案是做一个检查元素,看看哪个元素在影响它。
If you are not expert in than a best solution for you. 如果您不是专家,那么为您提供最佳解决方案。 Please add a new class just after dropdown-menu like: 请在dropdown-menu后添加一个新类,例如:

<ul class="dropdown-menu colorchange">

and call CSS by it like: 然后像这样调用CSS:

.colorchange li a:hover{

    background-color: green;

}

It should work! 它应该工作! You can use important here as well. 您也可以在这里使用important信息。

Try this 尝试这个

 .dropdown-menu li:hover .dropdown-menu li a{
        color: green;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM