Html 我如何将这些 Twitter bootstrap 3 导航栏链接居中?

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

How do I center these Twitter bootstrap 3 navbar links?

htmlcsscenteringnavbartwitter-bootstrap-3

提问by Ashley Brown

I'm wondering on how I can center the bootstrap 3's navbar menu items. I know they have included a .nav-justifiedclass but that will just conflict with navbar-navif used together. I belive it is being looked into by the dev team.

我想知道如何将引导程序 3 的导航栏菜单项居中。我知道他们已经包含了一个.nav-justified类,但navbar-nav如果一起使用,它就会发生冲突。我相信开发团队正在研究它。

So is there any work around with CSS that I can achieve a navbar that will keep the navbar menu items/links justified even when the container it is in is re-sized.

那么是否有任何使用 CSS 的解决方法,我可以实现导航栏,即使它所在的容器重新调整大小,导航栏菜单项/链接也将保持合理。

Here's a Jsfiddlefor you if you need it.

如果您需要,这里有一个Jsfiddle

回答by edsioufi

The .nav-justifedclass is to be used with nav-tabs/ nav-pills(see bootstrap docs) and not nav-bar. The two concepts are very different and should not be confused.

.nav-justifed类是与使用nav-tabs/ nav-pills(见引导文档),而不是nav-bar。这两个概念非常不同,不应混淆。

However, you can achieve the effect you are looking for by adding the following css:

但是,您可以通过添加以下内容来实现您正在寻找的效果css

.navbar-nav.nav-justified > li{
    float:none;
}

nav-justifiednow plays nice with navbar-nav:

nav-justified现在玩得很好navbar-nav

<ul class="nav navbar-nav nav-justified">

See updated jsFiddle.

请参阅更新的 jsFiddle

回答by X?pplI'-I0llwlg'I -

If using LESS, you can do the following:

如果使用 LESS,您可以执行以下操作:

.navbar-nav {
  .nav-justified;
}