html - 删除列表的边界半径而不覆盖全局(Bootstrap 3)

标签 html css twitter-bootstrap twitter-bootstrap-3

我正在使用 Bootstrap 3 创建一个小型应用程序。我需要使用他们的 linked list但不想要圆形边框。

在 CSS 文件中,他们使用以下内容:

.list-group-item:first-child {
  border-top-right-radius: 4px;
  border-top-left-radius: 4px;
}

.list-group-item:last-child {
  margin-bottom: 0;
  border-bottom-right-radius: 4px;
  border-bottom-left-radius: 4px;
}

目前,我使用以下方法覆盖类:

.list-group-item:first-child {
  border-top-right-radius: 0px !important;
  border-top-left-radius: 0px !important;
}

.list-group-item:last-child {
  border-bottom-right-radius: 0px !important;
  border-bottom-left-radius: 0px !important;
}

这样做的问题是,这使我呈现的所有列表都没有边框。有没有办法只覆盖我使用的这个单个实例?

这是一个关于如何使用它的 bootstrap 示例 (http://getbootstrap.com/components/#list-group-linked):

<div class="list-group">
  <a href="#" class="list-group-item active">
    Cras justo odio
  </a>
  <a href="#" class="list-group-item">Dapibus ac facilisis in</a>
  <a href="#" class="list-group-item">Morbi leo risus</a>
  <a href="#" class="list-group-item">Porta ac consectetur ac</a>
  <a href="#" class="list-group-item">Vestibulum at eros</a>
</div>

最佳答案

你能为你的 list-group 添加一个特殊的类名吗,比如 list-special?然后使用...

CSS

.list-special .list-group-item:first-child {
  border-top-right-radius: 0px !important;
  border-top-left-radius: 0px !important;
}

.list-special .list-group-item:last-child {
  border-bottom-right-radius: 0px !important;
  border-bottom-left-radius: 0px !important;
}

HTML

<div class="list-group list-special">
  <a href="#" class="list-group-item active">
    Cras justo odio
  </a>
  <a href="#" class="list-group-item">Dapibus ac facilisis in</a>
  <a href="#" class="list-group-item">Morbi leo risus</a>
  <a href="#" class="list-group-item">Porta ac consectetur ac</a>
  <a href="#" class="list-group-item">Vestibulum at eros</a>
</div>

演示:http://bootply.com/95585

编辑:使用 CSS 通常不是好的做法!重要。由于 list-special 提供了更多的特异性,您可以删除 !important。我更新了 Bootply,以便您了解其工作原理。

关于html - 删除列表的边界半径而不覆盖全局(Bootstrap 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20105818/

相关文章:

html - 根据浏览器大小缩放 HTML 页面

javascript - Angular 2 组件和 Bootstrap css 网格放置

html - 响应站点不工作 : CSS

javascript - 如何使用 Javascript 检测文本区域中的新空行?

jquery - 放置一个 div,使其看起来位于 mainwrapper (980px) 之外

Jquery 点击事件不工作

css - 是否可以在现有代码上使用 Bootstrap ?

jquery - 如何在 slider 更改时将类添加到 Bootstrap 缩略图

javascript - 使用 JavaScript 更改 Div 样式而无需重新加载页面

html - 如何使容器的子 div 与 IE7 中最大的子 div 的宽度相匹配?