twitter-bootstrap 单独的导航栏和导航栏内部类的目的是什么?

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

What's the purpose of separate navbar and navbar-inner classes?

csstwitter-bootstrap

提问by Tony

In Twitter bootstrap's starter-template.html, the navbar is written as

在 Twitter bootstrap 的 starter-template.html 中,导航栏被写成

<div class="navbar">
  <div class="navbar-inner">
    <div class="container">
    ...
    </div>
  </div>
</div>

However, if I change the markup to

但是,如果我将标记更改为

<div class="navbar navbar-inner">
  <div class="container">
  ...
  </div>
</div>

everything seems to work fine and there's no discernible visual differences as far as I can tell. What's the reason to have separate navbarand navbar-innerclasses associated with two divs? Why not just have a navbarclass that combines styles of both?

一切似乎都很好,据我所知,没有明显的视觉差异。与两个 div 关联的单独navbarnavbar-inner类的原因是什么?为什么不创建一个navbar结合了两者风格的类呢?

回答by Bass Jobsen

It makes the stucture of your html document more clear and readable. The .navbar class sets the position (and has a default display inline) while the navbar-inner class wraps the content of this container (display table). Your .navbar can contain more as one blocks like navbar-inner.

它使您的 html 文档的结构更加清晰易读。.navbar 类设置位置(并具有默认的内联显示),而 navbar-inner 类包装此容器的内容(显示表)。您的 .navbar 可以像 navbar-inner 一样包含多个作为一个块。

In your hierarchical DOM-structure .navbar has the same level as the .container(fluid) divs:

在您的分层 DOM 结构中,.navbar 与 .container(fluid) div 具有相同的级别:

enter image description here

在此处输入图片说明

回答by Paul Joiner

This is way old but I had the same question recently. I think the purpose is cosmetic.

这已经很老了,但我最近有同样的问题。我认为目的是美容。

I've noticed that .navbar-inner has a linear gradient background. With multiple rows of .navbar-inner, each nav row is more clearly defined for the end user.

我注意到 .navbar-inner 有一个线性渐变背景。使用多行 .navbar-inner,每个导航行都为最终用户更清晰地定义。

For each type of navbar style, .navbar-inner has different means of visually delineating it's content.

对于每种类型的导航栏样式, .navbar-inner 都有不同的方式来直观地描述其内容。