gpt4 book ai didi

css - z-index 高于下图的居中文本 (CSS)

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

我有几个嵌入了 img 的 div。我想在这些 div 中放置文本,但文本应位于图像上方。所以我写了下面的代码:

#headline-div {
z-index:100;
position:absolute;
text-align: center;
}
#divbgs1 {
z-index:1;
position:relative;
}

<div id="headline-div">
<span>Willkommen auf den Rook Islands...</span>
</div>
<div class="divbgs1">
<img src="/img/rook/img/flying.jpg"/>
</div>

但现在文字留给了图像,我无法将其居中。页面链接:http://bit.ly/1i7j47A

亲切的问候

最佳答案

首先,您的 html 中有 class="divbgs1",但在您的 css 中,您放置了 #divbgs1 而不是 .divbgs1 .我假设您的意思是将它作为一个类。

.divbgs1 {
text-align: center; //add this
z-index: 1; //remove this
position: relative;
padding: 10px; // you might want to add a padding, adjust accordingly
}

.divbgs1 img {
position: absolute;
top: 10px; //adjust these accordingly
left: 10px; //adjust these accordingly
}

关于css - z-index 高于下图的居中文本 (CSS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20934549/

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