我在页面上使用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>';
我想在课程活跃时改变li的背景:
li .active{
background-color: red;
}
但我的代码不起作用
答案 0 :(得分:4)
尝试
.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;
}
答案 1 :(得分:1)
答案 2 :(得分:1)
您可以使用此代码。
li.active{
background-color: red;
}
答案 3 :(得分:-1)
请尝试一下:
li.active{
background-color: red !important;
}