我能否在:before或:after中使用content:''属性的image url()时添加border-radius?
您可以在伪元素 ::after
和 ::before
中使用 border-radius
,并且还可以使用背景图片:
div:before {
content: "";
display: block;
width: 200px;
height: 100px;
background-image: url(http://placehold.it/200x100);
border-radius: 10px;
}
<div></div>
:before
或 :after
元素设置border-radius即可。
JSFiddle
#container {
background: red;
width: 100px;
height: 100px;
position: relative;
float: left;
}
#container:before {
content: '';
background: url('http://cdn.sstatic.net/stackoverflow/img/sprites.svg?v=1bc6a0c03b68') blue;
background-size: 1000px auto;
width: 100px;
height: 100px;
border-radius: 50px;
position: absolute;
}