我在引导程序中有一个导航栏,我正在尝试将导航栏项目设计为具有背景颜色,但是当我尝试这样做时,仍然有一些空间不会占用该背景颜色。如何让它覆盖整个屏幕?
@media (max-width: 992px) {
.navbar-collapse li a {
/* style goes here */
margin-top: 5px;
background-color: aqua;
border: 2px solid black;
}
}

<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<!-- jQuery first, then Tether, then Bootstrap JS. -->
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
</head>
<body>
<nav class="navbar navbar-toggleable-md navbar-inverse bg-inverse">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button>
<a class="navbar-brand" href="#"> <img src="images/brand.jpeg" width="30" height="30" class="d-inline-block align-top" alt=""> El Credor </a>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mx-auto">
<li class="nav-item "> <a class="nav-link" href="#"><span>product1</span></a> </li>
<li class="nav-item "> <a class="nav-link" href="#"><span>product2</span></a> </li>
<li class="nav-item"> <a class="nav-link" href="#"><span>product3</span></a> </li>
<li class="nav-item"> <a class="nav-link" href="#"><span>product4</span></a> </li>
<li class="nav-item"> <a class="nav-link" href="#"><span>product5</span></a> </li>
</ul> <a id="aboutUsRemove" class="navbar-brand aboutUs" href="#"> About Us </a> </div>
</nav>
</body>
</html>
&#13;
答案 0 :(得分:1)
.navbar的填充为1rem
,因此您需要在nav-link
@media (max-width: 992px) {
.navbar-nav .nav-item .nav-link {
/* style goes here */
margin-top: 5px;
background-color: aqua;
border: 2px solid black;
margin-left: -1rem;
margin-right: -1rem;
padding-left: 1rem;
}
}
答案 1 :(得分:0)
如果您想更改链接的背景,可以这样做。
<强>段强>
@media (max-width: 992px) {
.nav-link > span {
/* style goes here */
margin-top: 5px;
background-color: aqua;
border: 2px solid black;
}
}
&#13;
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<!-- jQuery first, then Tether, then Bootstrap JS. -->
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
</head>
<body>
<nav class="navbar navbar-toggleable-md navbar-inverse bg-inverse">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button>
<a class="navbar-brand" href="#"> <img src="images/brand.jpeg" width="30" height="30" class="d-inline-block align-top" alt=""> El Credor </a>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mx-auto">
<li class="nav-item "> <a class="nav-link" href="#"><span>product1</span></a> </li>
<li class="nav-item "> <a class="nav-link" href="#"><span>product2</span></a> </li>
<li class="nav-item"> <a class="nav-link" href="#"><span>product3</span></a> </li>
<li class="nav-item"> <a class="nav-link" href="#"><span>product4</span></a> </li>
<li class="nav-item"> <a class="nav-link" href="#"><span>product5</span></a> </li>
</ul> <a id="aboutUsRemove" class="navbar-brand aboutUs" href="#"> About Us </a> </div>
</nav>
</body>
</html>
&#13;
希望这有帮助!