gpt4 book ai didi

html - 如何用css画一条线并在上面显示文字或图片

转载 作者:行者123 更新时间:2023-11-28 08:35:47 25 4
gpt4 key购买 nike

我正在尝试使用 CSS 绘制一条线并在该线的中间显示文本/图像。

.featured-images {
color: #666666;
border: 2px solid #333333;
}
<p class="featured-images">Featured</p>

这就是我想要做的:

enter image description here

enter image description here

最佳答案

将文本包裹在 span 中,并为该行使用 :pseudo-element。

使用 z-index: -1 将行(:伪元素)放在 span 后面,这样您就可以在文本中移动而不必担心行。

.featured-images {
position: relative;
color: #666666;
border: 2px solid #333333;
padding: 0 10px 0 30px;
}
.featured-images span {
color: #666666;
background: white;
padding: 0 10px;
}
.featured-images:after {
content: '';
position: absolute;
width: 100%;
height: 2px;
background: #666666;
left: 0;
top: 50%;
transform: translateY(-50%);
z-index: -1;
}
<p class="featured-images"><span>Featured</span></p>


复制以下内容:

enter image description here

enter image description here

enter image description here

您可以使用repeating-linear-gradient 来做到这一点。

body {
background: #E7EAE3;
}
.featured-images {
position: relative;
color: #666666;
padding: 0 10px 0 30px;
overflow: hidden;
}
.featured-images span {
color: #517575;
background: white;
padding: 0 10px;
}
.featured-images:after {
content: '';
position: absolute;
width: 120%;
height: 100%;
background: -webkit-repeating-linear-gradient(180deg, #463A3A 10px, #F2F2F2 10px, #F2F2F2 11px, #463A3A 11px, #463A3A 20px) repeat-x;
background: -moz-repeating-linear-gradient(180deg, #463A3A 10px, #F2F2F2 10px, #F2F2F2 11px, #463A3A 11px, #463A3A 20px) repeat-x;
background-size: 10px 31px;
margin-left: -30px;
transform: skew(-45deg);
left: 0;
z-index: -1;
}
<p class="featured-images"><span>Featured</span>
</p>


使用图片代替文字。

.featured-images {
position: relative;
color: #666666;
border: 2px solid #333333;
padding: 0 10px 0 30px;
}
.featured-images span {
display: block;
width: 80px;
height: 13px;
background: url(http://lorempixel.com/80/13) no-repeat white 10px 0;
padding: 0 10px;
}
.featured-images:after {
content: '';
position: absolute;
width: 100%;
height: 2px;
background: #666666;
left: 0;
top: 50%;
transform: translateY(-50%);
z-index: -1;
}
<p class="featured-images"><span></span></p>

关于html - 如何用css画一条线并在上面显示文字或图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28044529/

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