老师,麻烦看看对不喽。后附一个问题~
来源:4-11 自由编程
慕仰5120631
2021-04-02 21:09:05
<!-- gallery -->
<div class="gallery">
<div class="galleryUp">
<h2>GALLERY</h2>
<div class="line"></div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting</p>
<p>industry. Lorem Ipsum has been the industry's standard dummy</p>
<p>text ever since the 1500s.</p>
</div>
<div class="galleryDown">
<dl>
<dt><img src="./images/03-01.jpg" alt=""></dt>
<dd>Science Lab</dd>
</dl>
<dl>
<dt><img src="./images/03-02.jpg" alt=""></dt>
<dd>Indoor Stadium</dd>
</dl>
<dl>
<dt><img src="./images/03-03.jpg" alt=""></dt>
<dd>Transportation</dd>
</dl>
<dl>
<dt><img src="./images/03-04.jpg" alt=""></dt>
<dd>Kids Room</dd>
</dl>
<dl>
<dt><img src="./images/03-05.jpg" alt=""></dt>
<dd>Meditation Classes</dd>
</dl>
<dl>
<dt><img src="./images/03-06.jpg" alt=""></dt>
<dd>Kids Play Ground</dd>
</dl>
</div>
</div>
<!-- footer -->
<footer>
<p>© 2016 imooc.com 京ICP备13046642号</p>
</footer>
</body>
.gallery .galleryUp h2{
font-size: 32px;
text-align: center;
padding-top: 30px;
}
.gallery .galleryUp .line{
width: 60px;
height: 3px;
background: #07cbc9;
margin: 10px auto;
}
.gallery .galleryUp p{
text-align: center;
color: gray;
font-size: 14px;
}
.gallery .galleryDown{
width: 1200px;
height: 650px;
margin: 0 auto;
/* background-color: #07cbc9; */
}
.gallery .galleryDown dl{
overflow: hidden;
float: left;
width: 360px;
height: 290px;
margin: 15px 20px;
}
.gallery .galleryDown dl dt img{
display: block;
}
.gallery .galleryDown dl dd{
color: white;
background-color: black;
height: 50px;
font-size: 16px;
padding-left: 10px;
padding-top: 10px;
}
footer{
height: 80px;
background-color: #07cbc9;
text-align: center;
line-height: 80px;
font-size: 15px;
}
问题描述:
老师,我为了让文字不贴边给dd标签加了padding,但是为什么dd标签黑色的背景没有对上呢?
1回答
同学你好,问题解答如下:
背景没对上是因为dl设置了固定高度和溢出隐藏:

由于dd设置了固定高度,所以padding-top会增大它的高度,导致dd有部分内容超出dl,从而被隐藏了:

同学可以把overflow:hidden;去掉看看:

代码中有如下问题:
1、直接运行同学的代码,在老师这里效果有问题:

建议补上如下样式,去除元素默认的间距:

(同学那里要是有该样式,则忽略该条)
2、图片底部的文字没有垂直居中:

建议使用行高实现其居中,如下:
祝学习愉快!
相似问题