gpt4 book ai didi

html - 在 Bootstrap 中使用 Div 在图像上显示文本

转载 作者:太空宇宙 更新时间:2023-11-04 02:43:30 25 4
gpt4 key购买 nike

我尝试使用下面的代码在图像上显示文本,如下所示;

enter image description here

<div class="wrapper">
<img src="https://cdn0.vox- cdn.com/thumbor/qLH7593e3D2SSSIdkwgBWdYhjjk=/289x0:802x684/400x533/filters:forma t(webp)/cdn0.vox-cdn.com/uploads/chorus_image/image/47859707/6621139883_e6be6a217a_b__1_.0.0.jpg" alt="" />
<div class="overlay">
<h2>Restaurant Stowaway Devours $800 of Roast Goose and Wine</h2>

</div>
</div>

CSS

body {
text-align: center;
}

.wrapper {
display: inline-block;
margin-top: 25px;
position: relative;
}

.wrapper img {
display: block;
max-width:100%;
}

.wrapper .overlay {
position: absolute;
top:0;
left:0;
width:100%;
height:100%;
background-color: rgba(0,0,0,0.25);
color:white;
}

但是结果是这样的: enter image description here

请帮帮我,我错过了什么?因为我希望输出像上面显示的第一张图片一样。

最佳答案

您必须将类添加到您的标题 h2 标记并向其添加以下样式。添加以下类,

 <h2 class="header">Restaurant Stowaway Devours $800 of Roast Goose and Wine</h2>

h2.header {
bottom: 0;
position: absolute;
text-align: center;
width: 100%;
}

关于html - 在 Bootstrap 中使用 Div 在图像上显示文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34251565/

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