html - 如何将margin-top添加到伪元素
问题描述
我试图在包含 css 伪元素的标题中添加边距顶部。
当尝试添加我的边距顶部时,伪元素(文本上方的行)嵌套在我的边距内。我怎样才能在它上面添加边距。
CSS
.line-top{
font-size: 32px;
font-weight: 200;
padding: 30px 0;
letter-spacing: 2px;
margin-top:5rem;
&::before{
position: absolute;
display: inline-block;
content: '';
background:
linear-gradient(
to left,
$orange 0,
$orange 50.00%,
$teal 50.00%,
$teal )no-repeat;
height: 4px;
width: 190px;
top: 15px;
}
}
HTML
<h3 class="line-top">ME Text Title </h3>
图片
解决方案
您正在将::before
伪元素设置为绝对位置,但是您没有在.line-top
. 因此,它将使用默认值(静态)。
您需要改用相对定位。
.line-top {
position: relative;
...
文档:https ://developer.mozilla.org/en-US/docs/Web/CSS/position
推荐阅读
- json - Can't Get Json to display in ag Grid 只是说正在加载
- authentication - 连接 Amazons EKS 以使用 Azures Active Directory 进行 RBAC
- php - 如何修复第 72 行 wp-includes/functions.php 中遇到的非数字值
- javascript - 如何在反应中修复/查找“错误请求”和“拒绝”身份验证错误
- perl - Perl Config::Simple:在文件中添加额外的控制字符 (\\n)
- excel - 对具有多列的范围进行排序,其中一列包含 1900 年之前的日期
- c# - 在 C# Linq 查询中丢弃
- php - 输入类型=文件不能接受大尺寸图片
- javascript - 我想更改条形图单个条的颜色
- neo4j - 在 neo4j-admin 导入后创建唯一约束时遇到无限重启