正确对齐伪选择器图像

问题描述 投票:0回答:2

如何为伪元素:before使用边距或填充以在图像和数字之间提供足够的空间

Look here in this link for screenshot

<!DOCTYPE html>
<html lang="en">
<head>
       <meta charset="UTF-8">
       <link rel="stylesheet" href="style.css">
       <title>Document</title>
</head>
<body>
     <div class="container">
        <ul>
            <li>city</li>
            <li>email</li>
            <li>adress</li>
            <li>0202020202</li>
        </ul>
      </div>

</body>
</html>

the code is here

非常感谢您的帮助

css pseudo-element
2个回答
0
投票

另一种解决方案是将pic显示为背景。然后,您可以轻松定位您的图标。

ul li:nth-child(4)::before {
    content: '';
    background: transparent url(image.png) no-repeat right top;
    background-size: contain;
    position: absolute;
    width: 25px;
    height: 30px;
    left: -30px;
    top: 0;
}

Here in your code


0
投票

根据您所需的prnscrn

你需要使用margin-left伪选择器的:before并将bottom放在0上。使用下面的CSS,它应该正确结果:

这是一个有效的fiddle

CSS

li:nth-child(4)::before {
    content: url('https://image.prntscr.com/image/RsidxDk_QzytthM_zz4H8Q.png');
    position: absolute;
    margin-left: -2.7em;
    bottom: 0;
    zoom: 0.8;
}

在这个例子中使用zoom减小margin-left单位em的大小和使用,所以它将采用元素的字体大小。 (还要注意,您提供的CSS中存在很多错误)。

© www.soinside.com 2019 - 2024. All rights reserved.