CSS Bootstrap:更改背景颜色下拉菜单

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23699773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 02:28:29  来源:igfitidea点击:

Bootstrap: Change Background Color Dropdown menu

csstwitter-bootstrapdrop-down-menubackground-color

提问by user3645310

At the moment i am using this template: http://getbootstrap.com/examples/navbar-fixed-top/

目前我正在使用这个模板:http: //getbootstrap.com/examples/navbar-fixed-top/

Is there any way to give the background in the dropdownmenu (The one that pops up, when the navbar collapses) another color than the navbar itself?

有什么方法可以在下拉菜单中为背景(导航栏折叠时弹出的那个)提供不同于导航栏本身的另一种颜色?

What i tried so far is this, without success:

到目前为止我尝试的是这样,但没有成功:

.navbar-default .navbar-nav .open .dropdown-menu > .active > a,
.navbar-default .navbar-nav .open .dropdown-menu > .active > a:hover,
.navbar-default .navbar-nav .open .dropdown-menu > .active > a:focus {
    color: #555555;
    background-color: #e7e7e7;
}

回答by Dragonfly

Use this

用这个

.navbar-nav > li > .dropdown-menu { background-color: #FF0000; }

回答by Jonathan Odle

Remember all you are doing with CSS is calling out what your HTML already reads. You need to get a tell the CSS what changes you want and from where. This code below should work with changing the background color of your drop down menu and the color of the font.

请记住,您使用 CSS 所做的一切就是调出您的 HTML 已经读取的内容。你需要告诉 CSS 你想要什么改变以及从哪里改变。下面的代码应该用于更改下拉菜单的背景颜色和字体颜色。

/* Dropdown menu background color*/

.navbar-nav > li > .dropdown-menu {     background-color: #e7e7e7;  }

/* Dropdown menu font color*/ 

 .navbar-nav > li > .dropdown-menu a{   color: #555555;  }

回答by Gurvir

Try this

尝试这个

.dropdown-menu > .active > a,.dropdown-menu > .active > a:hover.dropdown-menu > .active > a:focus {color: #555555!important; background-color: #e7e7e7!important;}

回答by Akanksha

To get the background color of Bootstrap Navigation Menu dropdowns

获取 Bootstrap 导航菜单下拉菜单的背景颜色

.navbar-nav > li > .dropdown-menu a:link,
.navbar-nav > li > .dropdown-menu a:hover { background-color: #FF0000;}

回答by Andrew Matthew

ul.dropdown-menu {
    background-color: #000;
}

回答by imdhemy

you can use a suitable @media screen value

您可以使用合适的@media 屏幕值

to change the parent ulbackground use the following code:

要更改父ul背景,请使用以下代码:

@media (max-width: 768px){
  .dropdown-menu{
    /*property: value;*/
  }
}

回答by wildnano

.nav .open>a {background: #yourcolor !important;}

回答by imhsgoraya

When dropdown menu clicked then an "open" class has added by bootstrap so you can overwrite as following:

单击下拉菜单时,引导程序添加了一个“打开”类,因此您可以按如下方式覆盖:

.navbar-default .navbar-nav > .open > a, 
.navbar-default .navbar-nav > .open > a:focus,
.navbar-default .navbar-nav > .open > a:hover {
    color: #555;
    background-color: #e7e7e7;
}