v3和v4中的Bootstrap面包屑组件在列表项中添加了一个“/”:

http://getbootstrap.com/components/#breadcrumbs

https://v4-alpha.getbootstrap.com/components/breadcrumb/

文档说:



因此,我查看了源代码,相关部分显示了:

.breadcrumb-item + .breadcrumb-item::before {
  display: inline-block;
  padding-right: 0.5rem;
  padding-left: 0.5rem;
  color: #636c72;
  content: "/";
}

但是,content: "/";仅存在于breadcrumb-item规则上。但是,当我遵循v3文档时,它似乎可以正常工作,对于列表中的元素,该文档不需要breadcrumb-item类:
<ol class="breadcrumb">
  <li class=''><a href="#">Home</a></li>
  <li class=''><a href="#">Library</a></li>
  <li class="active">Data</li>
</ol>

JSFiddle

为什么上面的HTML和上面的CSS会导致/分隔符添加到.breadcrumb列表中的元素,即使它们没有.breadcrumb-item类,因此也无法从content: "/"规则中受益呢?在JSFiddle中检查输出的HTML显示,没有引导Javascript魔术将.breadcrumb-item类添加到我的html列表项中。

最佳答案

链接到github(bootstrap v3.3.7)上的这种样式:

https://github.com/twbs/bootstrap/blob/v3.3.7/less/breadcrumbs.less

对于(bootstrap v4.0.0):

https://github.com/twbs/bootstrap/blob/v4.0.0-alpha.6/scss/_breadcrumb.scss

(bootstrap v3.3.7->面包屑.less)

//
// Breadcrumbs
// --------------------------------------------------


.breadcrumb {
  padding: @breadcrumb-padding-vertical @breadcrumb-padding-horizontal;
  margin-bottom: @line-height-computed;
  list-style: none;
  background-color: @breadcrumb-bg;
  border-radius: @border-radius-base;

  > li {
    display: inline-block;

    + li:before {
      content: "@{breadcrumb-separator}\00a0"; // Unicode space added since inline-block means non-collapsing white-space
      padding: 0 5px;
      color: @breadcrumb-color;
    }
  }

  > .active {
    color: @breadcrumb-active-color;
  }
}

(bootstrap v4.0.0-> _breadcrumb.scss)
.breadcrumb {
  padding: $breadcrumb-padding-y $breadcrumb-padding-x;
  margin-bottom: $spacer-y;
  list-style: none;
  background-color: $breadcrumb-bg;
  @include border-radius($border-radius);
  @include clearfix;
}

.breadcrumb-item {
  float: left;

  // The separator between breadcrumbs (by default, a forward-slash: "/")
  + .breadcrumb-item::before {
    display: inline-block; // Suppress underlining of the separator in modern browsers
    padding-right: $breadcrumb-item-padding;
    padding-left: $breadcrumb-item-padding;
    color: $breadcrumb-divider-color;
    content: "#{$breadcrumb-divider}";
  }

  // IE9-11 hack to properly handle hyperlink underlines for breadcrumbs built
  // without `<ul>`s. The `::before` pseudo-element generates an element
  // *within* the .breadcrumb-item and thereby inherits the `text-decoration`.
  //
  // To trick IE into suppressing the underline, we give the pseudo-element an
  // underline and then immediately remove it.
  + .breadcrumb-item:hover::before {
    text-decoration: underline;
  }
  + .breadcrumb-item:hover::before {
    text-decoration: none;
  }

  &.active {
    color: $breadcrumb-active-color;
  }
}

10-07 13:44