Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inset border-radius with CSS3

Tags:

css

css-shapes

Is there way to create inset border radius with css3? (Without images)

I need a border radius like this:

Inset border radius

like image 995
Serhiy Avatar asked Jun 14 '12 13:06

Serhiy


People also ask

How do you give inner border-radius in CSS?

Add a container for content The value should be equal to a CSS calc() function. The parameter for this function should be the expression based on the formula given above. To actually make the inner border-radius effect a background property with a value equal to the border color must be set to the . content element.

What is border-radius CSS3 property used for?

The border-radius CSS property rounds the corners of an element's outer border edge. You can set a single radius to make circular corners, or two radii to make elliptical corners.

What is inset CSS?

The inset CSS property is a shorthand that corresponds to the top , right , bottom , and/or left properties. It has the same multi-value syntax of the margin shorthand.


1 Answers

The best way I've found to achieve this with all CSS and HTML (no images, etc.) is by using CSS3 gradients, per Lea Verou. From her solution:

div.round {     background:         -moz-radial-gradient(0 100%, circle, rgba(204,0,0,0) 14px, #c00 15px),         -moz-radial-gradient(100% 100%, circle, rgba(204,0,0,0) 14px, #c00 15px),         -moz-radial-gradient(100% 0, circle, rgba(204,0,0,0) 14px, #c00 15px),         -moz-radial-gradient(0 0, circle, rgba(204,0,0,0) 14px, #c00 15px);     background:             -o-radial-gradient(0 100%, circle, rgba(204,0,0,0) 14px, #c00 15px),             -o-radial-gradient(100% 100%, circle, rgba(204,0,0,0) 14px, #c00 15px),             -o-radial-gradient(100% 0, circle, rgba(204,0,0,0) 14px, #c00 15px),             -o-radial-gradient(0 0, circle, rgba(204,0,0,0) 14px, #c00 15px);     background:             -webkit-radial-gradient(0 100%, circle, rgba(204,0,0,0) 14px, #c00 15px),             -webkit-radial-gradient(100% 100%, circle, rgba(204,0,0,0) 14px, #c00 15px),             -webkit-radial-gradient(100% 0, circle, rgba(204,0,0,0) 14px, #c00 15px),             -webkit-radial-gradient(0 0, circle, rgba(204,0,0,0) 14px, #c00 15px);     background-position: bottom left, bottom right, top right, top left;         -moz-background-size: 50% 50%;         -webkit-background-size: 50% 50%;     background-size: 50% 50%;     background-repeat: no-repeat; } 

The net result is a set of transparent gradients with curves. See the full JSFiddle for a demo and to play around with the way it looks.

Obviously this depends on support for rgba and gradient, and accordingly should be treated as a progressive enhancement, or if it's essential to the design, you should supply an image-based fallback for older browsers (especially IE, which doesn't support gradient even up through IE9).

like image 92
Chris Krycho Avatar answered Sep 17 '22 18:09

Chris Krycho