css - 如何在CSS伪元素class::after中添加填充顶部

标签 css html

我想将顶部填充添加到::after 并希望使其居中。

但这并没有发生,这就是我得到的:

enter image description here

使用此 CSS 后:

.list-unstyled li::after {
content: url(images/heartborder.png)
text-align:center;
padding-top: 30px;
}

这是我的 HTML 代码:

<li>
    <div class="col span-1-of-3 box">
        <span class="icon-small">
            <i class="fa fa-eye" aria-hidden="true"></i>
            <div class="details">
                <h5 class="heading">View / Edit Profile</h5>
                <p>You can view or edit your profile from here. Phone no., address, other information etc. etc.</p>
            </div>
        </span>
    </div>
</li>

最佳答案

您的 :after 默认设置为 display: inline,因此填充对其没有影响。将其更改为 inline-blockblock 即可。

要将其居中(按照评论中的要求),请在 div 上使用 flex,如下所示:

div {
  width: 50px;
  height: 50px;
  background: green;
  display: flex;
  justify-content: center;
}

div:after {
  content: "";
  width: 20px;
  height: 20px;
  background: blue;
  display: inline-block;
  padding-top: 5px;
}
<div></div>

关于css - 如何在CSS伪元素class::after中添加填充顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44409367/

相关文章:

javascript - jQuery 找出特定 X/Y 坐标处的内容?

javascript - 将 SVG 样式化为 React 组件

javascript - HTML 演示文稿幻灯片,调整元素大小以保持比例

javascript - 使用 HTML5 文件 API 循环读取多个文件

html - 将 html 表格单元格数据(具有一个表格和按钮)居中对齐

javascript - 我的简单 Javascript 代码可以在 Safari 上运行,但不能在 Chrome、Firefox 或 Opera 上运行,有什么问题吗?

html - 如何将此 div 的宽度设置为全屏宽度?

css - firefox:如何在首选项中设置黑色背景的输入字段中查看文本?

javascript - 如何根据贡献百分比计算前3名贡献者的领奖台高度?

html - 显示单元格宽度 : table