html – Bootstrap导航栏100%宽度不起作用

前端之家收集整理的这篇文章主要介绍了html – Bootstrap导航栏100%宽度不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的bootstrap导航栏上,即使导航栏位于图像顶部,我也试图在页面上进行完整操作.

但我已尝试在.navbar-wrapper和navbar以及navbar-default上宽度100%.但由于某种原因,导航栏仍然不会达到页面的整个宽度.

实例

这是我的codepen Code View

这是我的codepen Full View

问题如何使导航栏宽度100%工作,使其达到页面的整个宽度?

CSS

/* Special class on .container surrounding .navbar,used for positioning it into place. */
.navbar-wrapper {
    position: absolute;
    top: 0;
    right: 0;
    width: 100% !important;
    left: 0;
    z-index: 20;
}

/* Flip around the padding for proper display in narrow viewports */
.navbar-wrapper > .container {
    padding-right: 0;
    padding-left: 0;
}

.navbar-wrapper .navbar {
    padding-right: 15px;
    padding-left: 15px;
    width: 100% !important;
}

.navbar-inverse {
  width: 100% !important;
    background-color: rgba(0,0.5) !important;
}

.navbar-inverse .nav > li > a {
    color: #FFFFFF;
}

.navbar-inverse .nav > li > a:hover {
    background: none;
}

.navbar-brand a {
    color: #FFFFFF;
}

.main-header-background {
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-position: center; 
    background-image: url('./images/stars/img-stars-2.jpg');
    height: 620px;
    width: 100%;
    margin-bottom: 60px;
}

HTML

<div class="navbar-wrapper">
<div class="container">

<nav class="navbar navbar-inverse">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="navbar-brand">
<a href="#">Brand</a>
</div>
</div>

<!-- Collect the nav links,forms,and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

<ul class="nav navbar-nav">
<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
<li class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>

<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</li>
</ul>

</div><!-- /.navbar-collapse -->
</nav>
</div>
</div>

<div class="main-header-background">
</div>

解决方法

您可以通过使容器继承自“.navbar-wrapper”来使导航栏的宽度达到页面的整个长度.您可能还想删除“.navbar-wrapper .navbar”中设置的填充.

以下样式适合我:
见codpen:http://codepen.io/JordanLittell/pen/wadWxv

/ *围绕.navbar的.container上的特殊类,用于将其定位到位. * /

.navbar-wrapper {
    position: absolute;
    top: 0;
    right: 0;
    width: 100% !important;
    left: 0;
    z-index: 20;
}

/* Flip around the padding for proper display in narrow viewports */
.navbar-wrapper > .container {
    padding-right: 0;
    padding-left: 0;
    width: inherit;
}

.navbar-wrapper .navbar {
    width: 100% !important;
}

.navbar-inverse {
  width: 100% !important;
    background-color: rgba(0,0.5) !important;
  border-radius: 0;
}

.navbar-inverse .nav > li > a {
    color: #FFFFFF;
}

.navbar-inverse .nav > li > a:hover {
    background: none;
}

.navbar-brand a {
    color: #FFFFFF;
}

.main-header-background {
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-position: center; 
    background-image: url('http://www.riwakawebsitedesigns.com/external/images/stars/img-stars-2.jpg');
  height: 620px;
  width: 100%;
  margin-bottom: 60px;
}
原文链接:https://www.f2er.com/html/224650.html

猜你在找的HTML相关文章