css 在::before元素保持不变时移动文本

ih99xse1  于 2023-08-08  发布在  其他
关注(0)|答案(1)|浏览(98)

我试图创建一个自定义svg下划线的标题。结果应该是这样的:
x1c 0d1x的数据
到目前为止,我的代码看起来像这样:
超文本标记语言:

<div class="container">
    <div class="row">
        <h1 class="ml-4 underline-text">News feed</h1>
    </div>
</div>

字符串
CSS:

.underline-text {
    position: relative;
    display: inline-block;
    padding-bottom: 10px;
    &::before {
        content: "";
        background-image: url("./../../dist/img/underline.svg");
        background-repeat: no-repeat;
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 50px;
        z-index: -1;
    }
}


结果如下:



如何在不改变下划线位置的情况下移动文本?目前,它粘在Bootstrap网格的最左边,我觉得很好。但是,我想把文本向右移动一点。我试过使用ml-4,但它根本不起作用。同时,mx-4移动文本和下划线。如果我在CSS部分中设置margin-left,也会发生同样的情况。

slmsl1lt

slmsl1lt1#

而不是使用margin,使用padding,因为这不会影响伪元素的位置。

.underline-text {
  padding-left: 2rem !important;
}

字符串

相关问题