今天,我们来聊一聊如何使用CSS3去给图片下面添加横线。在CSS3中,使用伪元素可以很方便地实现这个效果。 首先,在HTML代码中,我们需要给图片和图片容器分别添加一个class,方便后面的CSS选择...
今天,我们来聊一聊如何使用CSS3去给图片下面添加横线。在CSS3中,使用伪元素可以很方便地实现这个效果。
首先,在HTML代码中,我们需要给图片和图片容器分别添加一个class,方便后面的CSS选择。代码如下:
<div class="img-container"> <img src="example.jpg" class="img" alt="Example"> </div>
.img-container{
position: relative;
}
.img-container:before{
content: ';
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 1px;
background-color: black;
} .img-container:before{
content: ';
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 1px;
background-color: gray;
border-radius: 5px;
}