【发布时间】:2021-06-06 06:28:51
【问题描述】:
我希望文本正好位于每张图片的中心,但它只是停留在它们上方。我为每个图像和文本项目使用一个 div,并使用一个通用 div 将所有这些项目放在一起。我确信有更有效的方法来组织它,但是我对 CSS 和 HTML 很陌生。
我正在使用的代码:
.projects {
width: 54%;
position: relative;
margin: auto;
}
.project {
position: relative;
margin: 0 auto;
width: 100%;
max-height: 600px;
min-height: 90px;
}
.project2 {
position: relative;
margin: 0 auto;
width: 100%;
max-height: 600px;
min-height: 90px;
}
.project3 {
position: relative;
margin: 0 auto;
width: 100%;
max-height: 600px;
min-height: 90px;
}
/* Caption text */
.text {
font-family: 'Verdana';
font-weight: bold;
font-size: 36px;
color: #FBB2B4;
text-decoration: none;
padding: 8px 12px;
position: relative;
top: 45%;
width: 100%;
text-align: center;
}
.text2 {
font-family: 'Verdana';
font-weight: bold;
font-size: 36px;
color: #FBB2B4;
text-decoration: none;
padding: 8px 12px;
position: relative;
top: 45%;
width: 100%;
text-align: center;
}
.text3 {
font-family: 'Verdana';
font-weight: bold;
font-size: 36px;
color: #FBB2B4;
text-decoration: none;
padding: 8px 12px;
position: relative;
top: 45%;
width: 100%;
text-align: center;
}
<div class="projects">
<div class="project">
<div class="text">heading1</div>
<img src="https://via.placeholder.com/150/" style="width:100%">
</div>
<div class="project2">
<div class="text2">heading2</div>
<img src="https://via.placeholder.com/150/" style="width:100%">
</div>
<div class="project3">
<div class="text3">heading3</div>
<img src="https://via.placeholder.com/150/" style="width:100%">
</div>
</div>
【问题讨论】: