我有5张照片:
每幅图片的大小如下:
图1: 70x40
图2: 80x42
图3: 90x44
图4: 100x46
图5: 120x48
我想把这些图片连在一起,排在一起。我也希望能够调整这些图片之间的距离,在CSS中,也是顶部和底部的边框。
如何创建div类并粘贴此代码以在页面上显示这些图片?另外,CSS是如何查找这个div类的,在这个类中,我可以调整图像之间的距离以及上、下边框的距离。
发布于 2015-01-13 07:24:00
您可以使用display: inline或float: left
*{box-sizing: bortder-box} /*lang-css*/
figure{
width: 100%;
}
img{display: inline; margin: 0 10px; border-top: 2px solid red; border-bottom: 4px solid green}
img:first-child{width: 70px; height: 40px}
img:nth-child(2){width: 80px; height: 42px}
img:nth-child(3){width: 90px; height: 44px}
img:nth-child(4){width: 100px; height: 46px}
img:last-child{width: 120px; height: 48px}<figure> <!--lang-html-->
<img src=https://pbs.twimg.com/media/B3bbgs9CMAA5Cwi.jpg />
<img src=https://pbs.twimg.com/media/B3bbgs9CMAA5Cwi.jpg />
<img src=https://pbs.twimg.com/media/B3bbgs9CMAA5Cwi.jpg />
<img src=https://pbs.twimg.com/media/B3bbgs9CMAA5Cwi.jpg />
<img src=https://pbs.twimg.com/media/B3bbgs9CMAA5Cwi.jpg />
</figure>
*{box-sizing: bortder-box} /*lang-css*/
figure{
width: 100%;
}
img{float: left; margin: 0 10px; border-top: 2px solid red; border-bottom: 4px solid green}
img:first-child{width: 70px; height: 40px}
img:nth-child(2){width: 80px; height: 42px}
img:nth-child(3){width: 90px; height: 44px}
img:nth-child(4){width: 100px; height: 46px}
img:last-child{width: 120px; height: 48px}<figure> <!--lang-html-->
<img src=https://pbs.twimg.com/media/B3bbgs9CMAA5Cwi.jpg />
<img src=https://pbs.twimg.com/media/B3bbgs9CMAA5Cwi.jpg />
<img src=https://pbs.twimg.com/media/B3bbgs9CMAA5Cwi.jpg />
<img src=https://pbs.twimg.com/media/B3bbgs9CMAA5Cwi.jpg />
<img src=https://pbs.twimg.com/media/B3bbgs9CMAA5Cwi.jpg />
</figure>
如果希望父标记处于居中位置,则需要在父标记上添加text-align: center。
*{box-sizing: bortder-box} /*lang-css*/
figure{
text-align: center;
width: 100%;
}
img{margin: 0 10px; border-top: 2px solid red; border-bottom: 4px solid green}
img:first-child{width: 70px; height: 40px}
img:nth-child(2){width: 80px; height: 42px}
img:nth-child(3){width: 90px; height: 44px}
img:nth-child(4){width: 100px; height: 46px}
img:last-child{width: 120px; height: 48px}<figure> <!--lang-html-->
<img src=https://pbs.twimg.com/media/B3bbgs9CMAA5Cwi.jpg />
<img src=https://pbs.twimg.com/media/B3bbgs9CMAA5Cwi.jpg />
<img src=https://pbs.twimg.com/media/B3bbgs9CMAA5Cwi.jpg />
<img src=https://pbs.twimg.com/media/B3bbgs9CMAA5Cwi.jpg />
<img src=https://pbs.twimg.com/media/B3bbgs9CMAA5Cwi.jpg />
</figure>
https://stackoverflow.com/questions/27916666
复制相似问题