gpt4 book ai didi

html - 如何在多个不同大小的图像上叠加文字? CSS

转载 作者:行者123 更新时间:2023-11-28 01:04:06 25 4
gpt4 key购买 nike

我有一个客户,她希望在每张图片左下角的所有已售出图片上方添​​加已售出的文字。我已经完成了实现,但问题是有些图像的大小不同。是否有一种“一类适合所有人”的 css 类型,我可以使用它来正确定位文本,而不管图像的大小如何?

代码:

.sold-overlay {
position: absolute;
top: 80%;
left: 59%;
width: 25%;
border: 1px solid #e60000;
color: white;
font-size: 50%;
background-color: red;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<div class="modal-body">
<h2>I Am Travon Martin</h2>
<img class="img-responsive img-centered" src="img/portfolio/sold/img-6847.jpg" alt="">
<h2 class="sold-overlay">Sold</h2>
<p>I'm sorry, this artwork has been sold to a happy customer.</p>
<button type="button" class="btn btn-primary" data-dismiss="modal"><i class="fa fa-times"></i> Close Project</button>
</div>
</div>
</div>
</div>

最佳答案

我将红色的已售出横幅放置在左下角,并将图像的大小调整为 100%,以便它始终填充其列/响应容器:

.sold-overlay {
position: absolute;
bottom: 0;
left: 0;
width: 25%;
border: 1px solid #e60000;
color: white;
font-size: 50%;
background-color: red;
}

.relative {
position: relative;
}

.relative img {
display: block;
width: 100%;
}
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<div class="modal-body">
<h2>I Am Travon Martin</h2>
<div class="relative">
<img class="img-responsive img-centered" src="http://placehold.it/200x100" alt="">
<div class="sold-overlay"><h2>Sold</h2></div>
</div>

<p>I'm sorry, this artwork has been sold to a happy customer.</p>

</div>
<button type="button" class="btn btn-primary" data-dismiss="modal"><i class="fa fa-times"></i> Close Project</button>
</div>
</div>
</div>

关于html - 如何在多个不同大小的图像上叠加文字? CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40698500/

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