Is there any way I can get a border-radius on a :before or :after when I put an image url() in the content:'' property?
A CSS pseudo-element is used to style specified parts of an element. For example, it can be used to: Style the first letter, or line, of an element. Insert content before, or after, the content of an element.
Unfortunately, border-radius isn't supported with border-image and it's painful to find tricks to obtain rounded borders having a gradient.
In CSS, ::before creates a pseudo-element that is the first child of the selected element. It is often used to add cosmetic content to an element with the content property. It is inline by default.
Yes you can use border-radius
in pseudo-elements ::after
, ::before
with an background image:
div:before {
content: "";
display: block;
width: 200px;
height: 100px;
background-image: url(http://placehold.it/200x100);
border-radius: 10px;
}
<div></div>
Just set border-radius in Your CSS rule, for :before
or :after
element.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With