麻烦老师看下【4-10 图片混排区域】的代码,图片右侧有空隙,不知道如何处理。

来源:4-10 自由编程

easyschen

2021-11-21 20:42:33

相关代码:HTML

<!-- ========================= 4-10 Word_Pic 图文区域 ⬇ ========================= -->

<div class="Word_Pic">
<div class="Word_Pic_1">
<div class="pic">
<img src="./images/b1.jpg" alt="pic1">
</div>
<div class="words">
<h3>Library</h3>
<p class="p1">
Lorem Ipsum is simply dummy text of the printing <br>
and typesetting industry
</p>
<p class="p2">
Lorem Ipsum has been the industry's standard dummy text ever  <br>
since the 1500s, when an unknown printer took a galley of type <br>
and scrambled it to make a type specimen book.<br>
</p>
<button>EXPLORE</button>
</div>
<div class="pic">
<img src="./images/b2.jpg" alt="pic1">
</div>
<div class="words">
<h3>Library</h3>
<p class="p1">
Lorem Ipsum is simply dummy text of the printing <br>
and typesetting industry <br>
</p>
<p class="p2">Lorem Ipsum has been the industry's standard dummy text ever  <br>
since the 1500s, when an unknown printer took a galley of type <br>
and scrambled it to make a type specimen book.<br>
</p>
<button>EXPLORE</button>
</div>
</div>
<div class="Word_Pic_2">
<div class="words">
<h3>Library</h3>
<p class="p1">
Lorem Ipsum is simply dummy text of the printing <br>
and typesetting industry <br>
</p>
<p class="p2">Lorem Ipsum has been the industry's standard dummy text ever  <br>
since the 1500s, when an unknown printer took a galley of type <br>
and scrambled it to make a type specimen book.<br>
</p>
<button>EXPLORE</button>
</div>
<div class="pic">
<img src="./images/b3.jpg" alt="pic1">
</div>
<div class="words">
<h3>Library</h3>
<p class="p1">
Lorem Ipsum is simply dummy text of the printing <br>
and typesetting industry <br>
</p>
<p class="p2">Lorem Ipsum has been the industry's standard dummy text ever  <br>
since the 1500s, when an unknown printer took a galley of type <br>
and scrambled it to make a type specimen book.<br>
</p>
<button>EXPLORE</button>
</div>
<div class="pic">
<img src="./images/b4.jpg" alt="pic1">
</div>
</div>

</div>

相关代码:CSS

/*============================== 4-10 Word_Pic 图文区域 ⬇ ================================*/
.Word_Pic{
width: 100%;
margin:0 auto;
}
.Word_Pic .Word_Pic_1{
overflow: hidden;
}
.Word_Pic .Word_Pic_2{
overflow: hidden;
}
.Word_Pic .pic{
float: left;
width: 25%;
height: 380px;       /*Q1:这里可以不设置高吗?*/
}
.Word_Pic .pic img{       /*Q2:图片这里的显示效果有点问题,视窗缩小70%以下的时候,图片右侧有空*/
display: block;
}
.Word_Pic .words{
float: left;
width: 25%;
height: 380px;
background: #07cbc9;
}
.Word_Pic .words h3{
font-size: 24px;
color: white;
padding:20px 0 20px 20px;
}
.Word_Pic .words .p1{
padding: 10px 20px;
color: white;
font-size: 16px;
}
.Word_Pic .words .p2{
padding: 10px 20px;
color: gray;
font-size: 14px;
}
.Word_Pic .words button{    /*Q3:button是行内块元素吗?行内元素可以设置宽高的就是行内块吧*/
display:block;
width: 138px;
height: 40px;
background: #000;
color: white;
line-height: 40px;
text-align: center;
border: none;
margin:0 auto;
margin-top: 20px;
}


问题描述:

Q1:这里可以不设置高吗?

相关截图:

https://img.mukewang.com/climg/619a3dae096b324507840186.jpg


问题描述:

Q2:图片这里的显示效果有点问题,视窗缩小70%以下的时候,图片右侧有空

相关截图:

https://img.mukewang.com/climg/619a3de509f14cda03560120.jpg

https://img.mukewang.com/climg/619a3e3809d34f1f17001248.jpg


问题描述:

Q3:button是行内块元素吗?行内元素可以设置宽高的就是行内块吧

相关截图:

https://img.mukewang.com/climg/619a3e5d0942288d04140462.jpg


问题描述:

Q4:麻烦老师看下代码有其他需要优化的部分吗?

写回答

1回答

好帮手慕然然

2021-11-22

同学你好,图片右侧有缝隙是因为图片的宽度不够,建议设置100%的宽度即可,与外层盒子大小保持一致,如图

https://img.mukewang.com/climg/619af965091fd21109040180.jpg

问题解答:

1、.pic最好设置一下高度,让所有图文盒子保持一致大小。

2、问题2上面已解答

3、button是行内块元素,行内块元素支持宽高,行内元素不支持宽高。

4、其它优化:代码整体实现效果没问题,不需要优化。

祝学习愉快!

1
hasyschen
hp>麻烦然然老师了。十分感谢。



h021-11-22
共1条回复

0 学习 · 15276 问题

查看课程