css - Bootstrap 4间距错误?

标签 css bootstrap-4

Bootstrap 4 有 Spacing Utilities使用简单的 CSS 类调整边距和填充。

理论上,我可以这样做:

<div class="d-inline-block bg-inverse p-5 pb-0 m-5 mb-0"></div>

这应该是一个在每一侧都具有填充和边距的元素底部除外。对吧?

但这并没有发生。相反,pb-0mb-0p-5m-5 覆盖,因为你可以在这里看到: example in JSFiddle .


pb-0mb-0 定义在 p-5m-5 之后原始来源,以及这些类中使用的所有属性都有 !important。所以 pb-0 应该覆盖 p-5 定义的 padding-bottommb-0 应该覆盖margin-bottomm-5 定义。

我创建了另一个示例,其中我以相同的方式定义了这些类,但在这种情况下,它们按预期工作:comparison example in JSFiddle .


为什么这些 Bootstrap 4 类没有按预期工作?

最佳答案

间距实用程序使用 !important所以,使用 pb-0覆盖 p-5不会工作,因为 p-5关注pb-0bootstrap.css

得到它working like you want设置具体的边...

<div class="d-inline-block bg-inverse pb-0 px-5 pt-5 mb-0 ml-5 mt-5"></div>

而且,由于默认情况下 DIV 没有填充或边距,因此您实际上并不需要 *-0 ...

<div class="d-inline-block bg-inverse px-5 pt-5 ml-5 mt-5"></div>

https://www.codeply.com/go/6hSIEizfMd


另见 when it's OK to use !important

关于css - Bootstrap 4间距错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49153205/

相关文章:

html - Bootstrap : Toggler not displaying its content

css - 如何使用 CSS 垂直集中 Bootstrap V4 模态?

html - Bootstrap NavBar 折叠在点击时不起作用

html - 使用 Chrome 放大时文本模糊

html - 所有网站的 CSS 修复或 CSS 重置

html - 允许元素在表布局 :fixed 的表中溢出

html - 为什么容器与我的侧边栏 <nav> 重叠?

javascript - Vuejs 将 HTML 转换为纯文本

html - 无法在 UL + LI (CSS) 中隐藏 HTML

css - 如何将卡片组与设置宽度的卡片结合起来?