html - :before :after pseudo selector without content?的目的是什么

标签 html css

我正在阅读一篇关于边框框的文章。

http://www.paulirish.com/2012/box-sizing-border-box-ftw/

作者推荐以下 CSS 代码:

/* apply a natural box layout model to all elements, but allowing components to change */
html {
  box-sizing: border-box;
}

*, *:before, *:after {
 box-sizing: inherit;
}

我知道 :before 和 :after 用于插入内容并设置插入内容的样式。

但是没有内容的 :before 和 :after 的目的是什么?

谢谢

最佳答案

.ribbon {
   background-color: #5BC8F7;
}

.ribbon::before {
   content:          "Look at this orange box.";
   background-color: #FFBA10;
   border-color:     black;
   border-style:     dotted;
  padding: 2rem;
margin:2rem;
}
<span class="ribbon">Notice where the orange box is.</span>

如您所见,内边距和边距可适用于 :之前 在它们上应用框大小调整是一种很好的技术。

关于html - :before :after pseudo selector without content?的目的是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32426114/

相关文章:

java - JSoup 无法获得 Google 搜索结果的正确日期范围

javascript - 创建在应用程序加载时调用方法的 AngularJS 对象

CSS 媒体查询在灯箱打开时被覆盖

javascript - 如何在没有内联脚本的情况下异步加载 CSS(符合 CSP)

html - 表单调整响应问题文本区域

html - 高度未知的中心元素不占用空间

html - float 在 chrome 中被覆盖

css - 具有可滚动内容区域填充剩余视口(viewport)区域的可变高度标题

CSS悬停停止动画

javascript - jquery 通过 id 选择当前正在播放的音频