gpt4 book ai didi

html - 图片上的文字顶部居中对齐

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

所以我希望图像上的文字水平居中。然后调整窗口大小它仍然在那里。 It have look like that.现在它在图像的底部。

.main_image {
display: block;
width: 90%;
height: auto;
margin-left: auto;
margin-right: auto;
border: 1px solid;
}
.image_text {
font-family: "Open Sans";
text-align: left;
border: 1px solid;
position: relative;
bottom: 50%;
transform: translateY(-50%);
}
.main_text {
font-size: 38.889px;
color: #000;
font-weight: bold;
text-transform: uppercase;
}
.main_subtext {
font-size: 22.222px;
color: rgba(0, 0, 0, 0.988);
}
<figure class="images_class">
<img src="http://i.imgur.com/sOCyriP.png" alt="" class="main_image" />
<figcaption class="image_text">
<div class="main_text">Main text</div>
<div class="main_subtext">Subtext</div>
</figcaption>
</figure>

最佳答案

您应该将文本 absolute 放置在 relative 容器中。

.images_class {
position: relative;
}
.main_image {
display: block;
width: 90%;
height: auto;
margin-left: auto;
margin-right: auto;
border: 1px solid;
}
.image_text {
font-family: "Open Sans";
text-align: center;
border: 1px solid;
width: 90%;
margin: auto;
position: absolute;
top: 0;
left: 0;
right: 0
}
.main_text {
font-size: 38.889px;
color: #000;
font-weight: bold;
text-transform: uppercase;
}
.main_subtext {
font-size: 22.222px;
color: rgba(0, 0, 0, 0.988);
}
<figure class="images_class">
<img src="http://i.imgur.com/sOCyriP.png" alt="" class="main_image" />
<figcaption class="image_text">
<div class="main_text">Main text</div>
<div class="main_subtext">Subtext</div>
</figcaption>
</figure>

关于html - 图片上的文字顶部居中对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28660880/

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