【发布时间】:2020-01-07 11:41:19
【问题描述】:
我试图让我的字幕在调整屏幕宽度时响应。我发现我的图片的一列(左侧)有一个标题,但第二列的标题没有,并且位于第一列的下方,除非我专门定位它们(然后它们没有响应)。如何让我的标题在调整大小时和其他情况下都贴在相应的图片上?
我已将图像的位置设置为相对位置,而 figcaption 设置为绝对位置。我已经尝试定位封装图片和标题的 div,移除浮动等。
img {
padding-top: 15px;
float: left;
padding-right: 15px;
position: relative;
}
#pic2 {
background-color: #4aaaa5;
;
text-align: center;
position: absolute;
top: 297px;
z-index: 1;
padding: 15px 110px;
color: white;
}
#pic1 {
background-color: #4aaaa5;
;
text-align: center;
position: absolute;
top: 297px;
z-index: 1;
padding: 15px 135px;
color: white;
}
#pic3 {
background-color: #4aaaa5;
;
text-align: center;
position: absolute;
top: 463px;
z-index: 1;
padding: 15px 133px;
color: white;
}
#pic4 {
background-color: #4aaaa5;
;
text-align: center;
position: absolute;
top: 463px;
left: 534px;
z-index: 1;
padding: 15px 120px;
color: white;
}
#pic5 {
background-color: #4aaaa5;
text-align: center;
position: absolute;
top: 627px;
padding: 15px 137.5px;
color: white;
}
<body>
<div class="wrapper">
<h1 class="header1">Portfolio</h1>
<div class="wrapper2">
<fig>
<div class="gallery1">
<img id="Pic1" src="./assets/images/download.jpg" height="150px" width="33.3%">
<figcaption id="pic1">Island</figcaption>
</fig>
<fig>
<div class="gallery2">
<img id="Pic2" src="./assets/images/d2.jpg" height="150px" width="33.3%">
<figcaption id="pic2">Track & Field</figcaption>
</div>
</fig>
<fig>
<div class="gallery3">
<img id="Pic3" src="./assets/images/d3.jpg" height="150px" width="33.3%">
<figcaption id="pic3">Bambi</figcaption>
</div>
</fig>
<fig>
<div class="gallery4">
<img id="Pic4" src="./assets/images/d4.jpg" height="150px" width="33.3%">
<figcaption id="pic4">City Scape</figcaption>
</div>
</fig>
<fig>
<div class="gallery5">
<img id="Pic5" src="./assets/images/d5.jpg" height="150px" width="33.3%">
<figcaption id="pic5">"Art"</figcaption>
</div>
</fig>
</div>
</div>
</div>
【问题讨论】:
-
欢迎来到 StackOverflow!请花一些时间正确格式化您的代码。此外,您的代码有很多错误,请尝试使用在线代码验证器之一,然后发布您的代码。最后但同样重要的是,请注意您可以使用stack snippets
标签: html css image responsive caption