CSS Twitter Bootstrap - 全宽导航栏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13085962/
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
Twitter Bootstrap - full width navbar
提问by StackOverflowNewbie
Following the example of TB, I have a navbar that is marked up as follows:
以 TB 为例,我有一个导航栏,其标记如下:
<div class="container">
<div class="navbar">
<div class="navbar-inner">
<!-- nav bar items here -->
</div>
</div>
</div>
I'd like this to span the full width of the screen and not have any rounded corners -- similar to static top styling of the navbar.
我希望它跨越屏幕的整个宽度并且没有任何圆角——类似于导航栏的静态顶部样式。
I can't seem to find how to do this in TB. If there isn't a way, what CSS would I need to override TB and not break responsiveness?
我似乎无法在 TB 中找到如何做到这一点。如果没有办法,我需要什么 CSS 来覆盖 TB 而不会破坏响应能力?
回答by Arnaud Bouchot
Just change the class container to container-fullwidth like this :
只需将类容器更改为 container-fullwidth ,如下所示:
<div class="container-fullwidth">
回答by ahsteele
Not sure if the navbar-static-top
class was available prior to version 2.2.2 but I think you can accomplish your goal with the following:
不确定该navbar-static-top
课程在 2.2.2 版之前是否可用,但我认为您可以通过以下方式实现您的目标:
<div class="navbar navbar-static-top">
<div class="navbar-inner">
<ul class="nav">
<li class="active"><a href="#">Test1</a></li>
<li><a href="#">Test2</a></li>
<li><a href="#">Test3</a></li>
<li><a href="#">Test4</a></li>
<li><a href="#">Test5</a></li>
</ul>
</div>
</div>
<div class="container">
...
</div>
I put together a jsFiddle as an example.
我整理了一个jsFiddle 作为例子。
回答by RRikesh
Put the navbar out of your container:
将导航栏从容器中取出:
<div class="navbar">
<div class="navbar-inner">
<!-- nav bar items here -->
</div>
</div>
<div class="container">
</div>
EDIT:
编辑:
Here is one that I did with responsive navbar. The code fits the document body:
这是我用响应式导航栏做的一个。代码适合文档正文:
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<!-- Be sure to leave the brand out there if you want it shown -->
<a class="brand" href="#">Project name</a>
<!-- Everything you want hidden at 940px or less, place within here -->
<div class="nav-collapse">
<!-- .nav, .navbar-search, .navbar-form, etc -->
<ul class="nav">
<li class="active"><a href="#">Home</a></li>
<li class="divider-vertical"></li>
<li><a href="#">Link</a></li>
<li class="divider-vertical"></li>
<li><a href="#">Link</a></li>
</ul>
<ul class="nav pull-right">
<li><a href="#">Log out</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="span12">
</div>
</div>
</div> <!-- end container -->
<script type="text/javascript" src="/assets/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="/assets/js/bootstrap.min.js"></script>
回答by Chris
I'm very late to the party but this answer pulls up top in Google search results.
我参加聚会很晚,但这个答案在谷歌搜索结果中名列前茅。
Bootstrap 3 has an answer for this built in, set your container div in your navbar to container-fluid
and it'll fall to screen width.
Bootstrap 3 对此有一个内置的答案,将导航栏中的容器 div 设置为container-fluid
,它会降到屏幕宽度。
Like so:
像这样:
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="/">More Stuff</a></li>
</ul>
</div>
</div>
</div>
回答by stack_overflower
Just replace <div class="container">
with <div class="container-fluid">
, which is the container with no margins on both sides.
只需替换<div class="container">
为<div class="container-fluid">
,即两侧没有边距的容器。
I think this is the best solution because it avoids some useless overriding and makes use of built-in classes, it's clean.
我认为这是最好的解决方案,因为它避免了一些无用的覆盖并使用了内置类,它很干净。
回答by Gayathra Nakandala
Put your <nav>
element out from the <div class='container-fluid'>
.
Ex :-
将您的<nav>
元素从<div class='container-fluid'>
. 例如:-
<nav>
......nav content goes here
<nav>
<div class="container-fluid">
<div>
........ other content goes here
</div>
</div>
回答by Ravi
You need to push the container down the navbar.
您需要将容器推下导航栏。
Please find my working fiddle here http://jsfiddle.net/meetravi/aXCMW/1/
请在这里找到我的工作小提琴http://jsfiddle.net/meetravi/aXCMW/1/
<header>
<h2 class="title">Test</h2>
</header>
<div class="navbar">
<div class="navbar-inner">
<ul class="nav">
<li class="active"><a href="#">Test1</a></li>
<li><a href="#">Test2</a></li>
<li><a href="#">Test3</a></li>
<li><a href="#">Test4</a></li>
<li><a href="#">Test5</a></li>
</ul>
</div>
</div>
<div class="container">
</div>
回答by silviomoreto
You can override some css
你可以覆盖一些css
body {
padding-left: 0px !important;
padding-right: 0px !important;
}
.navbar-inner {
border-radius: 0px !important;
}
The !important
is needed just in case you link the bootstrap.css
after your custom css.
该!important
以防万一你的链接,需要bootstrap.css
您自定义CSS后。
And add your nav html out of a .container
并添加您的导航 html .container
回答by Joseph N.
To remove the border-radius on the corners add this style to your custom.css file
要删除角上的边框半径,请将此样式添加到您的 custom.css 文件中
.navbar-inner{
-webkit-border-radius: 0; -moz-border-radius: 0; border-radius: 0;
}
回答by Eleanor Zimmermann
I know I'm a bit late to the party, but I got around the issue by tweaking the CSS to have the width span 100%, and setting l/r margins to 0px;
我知道我参加聚会有点晚了,但是我通过调整 CSS 使宽度跨度为 100% 并将 l/r 边距设置为 0px 来解决这个问题;
#div_id
{
margin-left: 0px;
margin-right: 0px;
width: 100%;
}