Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I put a border radius on a before or after pseudo selector image?

Tags:

html

css

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?

like image 639
Justin Wagner Avatar asked Mar 05 '15 17:03

Justin Wagner


People also ask

What do the pseudo selectors before and after allow you to do?

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.

Does border-radius work with Border image?

Unfortunately, border-radius isn't supported with border-image and it's painful to find tricks to obtain rounded borders having a gradient.

What is before pseudo selector in CSS?

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.


2 Answers

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>
like image 106
Alex Char Avatar answered Oct 18 '22 11:10

Alex Char


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;
}
like image 35
Mateusz Mania Avatar answered Oct 18 '22 13:10

Mateusz Mania