我不确定是脑子冻结还是缺乏知识。这应该是非常简单的,但我无法让它工作:
我有一个pseudo
元素,我想要将其绝对定位
(因此它被从流中取出并且不会扭曲其他元素)
并且
我希望伪元素与其当前位置偏移,例如仅向左偏移20像素。
我不能使用通过left: __px
从父级进行典型定位偏移,因为它在不同屏幕尺寸上会导致问题。
请问有人能告诉我如何实现这一点吗?
非常感谢!
JSFIDDLE:https://jsfiddle.net/AlphaX/pcsa2ow6/
.x_cta_error_msg {
line-height: 1.5;
background-color: lightgreen;
padding: 10px 15px 10px 45px;
height: 50px
}
.x_cta_error_msg::before, .x_simple_cta_error_msg::before {
font-family: "Font Awesome 5 Free";
font-weight: 900;
content: "\f06a";
font-size: 18px;
position: absolute;
}
<div style="position: relative">
<div class="x_cta_error_msg">
Some text that will be here to showing to the user as an info through the journey of making a booking.
</div>
</div>
<!-- just loading the fontawesome icon -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css" integrity="sha512-HK5fgLBL+xu6dm/Ii3z4xhlSUyZgTT9tuc/hSrtw6uzJOvgRr2a9jyxxT1ely+B+xFAmJKVSTbpM/CuL7qxO8w==" crossorigin="anonymous" />
x_cta_error_msg
,然后在图标上简单地使用left:Xpx。 - undefined