gpt4 book ai didi

css - 通过 :after 在下一行添加标题属性

转载 作者:行者123 更新时间:2023-11-28 10:57:50 25 4
gpt4 key购买 nike

在我的 website 上,我得到了几张链接到各种服务的图片。今天,我想在图像下添加服务名称。该名称已经在 anchor 标签的标题属性中,所以我认为这应该很容易。我这样试过:

a[title]:after{
content:"\A" attr(title);
font-size:10px;
text-decoration: underline;
}

问题是:换行符被忽略,文本显示为内联。有什么解决办法吗?

最佳答案

您可以使用 display: block 来强制换行,但这似乎要求父 a 也是 显示: block

a {
display: block;
}

a[title]:after{
display: block;
content: attr(title);
font-size:10px;
text-decoration: underline;
}

...或者,您可以使用 position: absolute;,尽管这也意味着将 CSS 添加到您的 a 样式定义中:

a: {
position: relative;
/* ...everything else...*/
}

a[title]:after{
position: absolute;
top: 1em; /* assuming your 'a' font-size is 1em, with no line-height/padding, adjust to taste */
left: 0; /* assuming you want it aligned with the left-hand side of the parent 'a' */
content: attr(title);
font-size:10px;
text-decoration: underline;
}

演示已添加到 JS Bin

关于css - 通过 :after 在下一行添加标题属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3850156/

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