gpt4 book ai didi

html - 带列表的数据图标

转载 作者:行者123 更新时间:2023-11-28 18:33:34 30 4
gpt4 key购买 nike

当我使用 data-icon 属性时,我的 css 有点问题。

我使用 :before 属性来做到这一点,我的图标显示在它的顶部,而不是我想要的左侧。

enter image description here

CSS:

[data-icon]:before {
font-family: 'icons';
content: attr(data-icon);
speak: none;
font-weight: normal;
-webkit-font-smoothing: antialiased;
}

HTML:

<ul class="tags" data-icon="&#x54;">
<li>Petrole</li>
<li>Gazoil</li>
<li>BP</li>
<li>Car</li>
</ul>

希望你能想通。

最佳答案

您可以相对于其元素绝对定位图标:

[data-icon] {
padding-left: 20px; /* Horizontal space for icon and some gap. */
position: relative;
min-height: 14px; /* Height of icon. */
}

[data-icon]:before {
position: absolute;
left: 0;
top: 0;
}

另一种可能的方法是对元素和生成的伪元素图标使用display: inlinedisplay: inline-block:

[data-icon]:before,
[data-icon] > LI {
display: inline;
}

关于html - 带列表的数据图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13543611/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com