css - 在 Bootstrap 列周围添加一致的 1px 边框

标签 css twitter-bootstrap bootstrap-4 twitter-bootstrap-4

是否有一种干净的、纯 CSS 的方法可以在列周围添加一致的 1px 边框,而当两个并排时,你没有 2px 边框?请注意外边缘如何具有 1 像素边框,而内边框是双倍宽度,因为它们是并排的。基本上,我想要表格单元格边框,但具有网格的响应能力。

#example {
  padding: 20px;
}

#example .col {
  border: 1px solid #c9c9c9;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.css" rel="stylesheet"/>


<div id="example">
  <div class="row">
    <div class="col">
      1st col
    </div>
    <div class="col">
      2nd col
    </div>
    <div class="col">
      3rd col
    </div>
  </div>
  <div class="row">
    <div class="col">
      4th col
    </div>
    <div class="col">
      5th col
    </div>
  </div>
</div>

最佳答案

您只需选择适当的列,并根据需要删除 border-right 和 border-bottom...

https://www.codeply.com/go/9S36zcuDGM

/* remove from last col in each row */
#example .col:not(:last-child) {
  border-right-width: 0;
}

/* remove from cols in last row */
#example .row:not(:last-child) .col {
  border-bottom-width: 0;
}

或者,您可以使用 border utils在 HTML 标记中(不理想)...

  <div class="row">
    <div class="col border border-right-0">
      1st col
    </div>
    <div class="col border border-right-0">
      2nd col
    </div>
    <div class="col border">
      3rd col
    </div>
  </div>

关于css - 在 Bootstrap 列周围添加一致的 1px 边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48790274/

相关文章:

node.js - 如何在我的 Node.js 项目中自动执行编译前端框架(如 Twitter Bootstrap)的任务?

javascript - 带有 HTML5 表单验证问题的 SASS 隔离

javascript - 根据 chrome 浏览器,mozilla 上的高度显示不相等

css - Angular:单元格的 innerHtml 中的 CSS 类用法

css - 无法弄清楚为什么 CSS 仅导致我的一个页面在移动设备中显示不正确?

html - iframe 在 Chrome 中转义 css 列

css - 如何使用 img-fluid,设置自定义高度而不变形图像?

php - 如何在嵌入 php 代码的情况下创建 html 元素的样式?

html - Bootstrap垂直滚动不流畅

jquery - Twitter Bootstrap 工具提示() 停止工作