twitter-bootstrap 使用类活动 Bootstrap 更改 li 的 css

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41376504/
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-10-22 00:28:45  来源:igfitidea点击:

Change css for li with class active Bootstrap

htmlcsstwitter-bootstrap

提问by Nastya Gorobets

I use Bootstrap on my page:

我在我的页面上使用 Bootstrap:

<?php echo '<div class="navbar navbar-default" role="navigation">
<div class="container-fluid">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="index.php">Project name</a>
    </div>
    <div class="navbar-collapse collapse">
        <ul class="nav navbar-nav">
            <li class="active" id="one"><a href="index.php">Home</a></li>';?   >
 <?php
 if (isset($_COOKIE['id']) and isset($_COOKIE['hash'])) {
 echo '<li><a href="logout.php">Logout</a></li>';
 }
 ?>
 <?php echo '</ul>
    </div>
 </div>
 </div>';

I want to change background for li with class active:

我想在类处于活动状态时更改 li 的背景:

 li .active{
    background-color: red;
}

But my code doesn't work

但我的代码不起作用

回答by Roy Bogado

Try

尝试

.navbar-default .navbar-nav > .active{
  color: #000; background: red;
}
.navbar-default .navbar-nav > .active > a, 
.navbar-default .navbar-nav > .active > a:hover, 
.navbar-default .navbar-nav > .active > a:focus {
  color: #000;
  background: red;
}

回答by Falguni Panchal

remove space between li . activechanged li.activeelements

删除li . active更改li.active元素之间的空间

css

css

 li.active{
    background-color: red;
}

Demo

演示

回答by Vijay Sharma

You can use this code.

您可以使用此代码。

li.active{
    background-color: red;
}

回答by illeas

Please try it :

请尝试:

li.active{
    background-color: red !important;
}