Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple borders, with padding, around image

Tags:

css

image

border

I want to create multiple border, with some padding, around my image like shown below. I prefer to do this with CSS only, but I don't know if this is possible.

While I googled for this I only found examples like this with multiple borders directly around the object using box shadow.

I tried creating this just using a border and padding around the image. But the padding didn't even worked out and with box-shadow like in the example above I won't get something like I want.

How would you guys handle this problem, and is it even possible?

Edit: Sorry, forget to show what I've currently have: code pen link

This is what I want to make

like image 797
ronnyrr Avatar asked Oct 30 '13 09:10

ronnyrr


People also ask

Can you have 2 borders CSS?

Multiple borders in CSS can be done by box-shadow property. Generally, we can get a single border with border property. Box-shadow property is not for multiple borders, but still, we are creating multiple borders with box-shadow property.

How do you make multiple borders in HTML?

Using pseudo element(s) The element needing multiple borders should have its own border and relative positioning. The secondary border is added with a pseudo element. It is set with absolute positioning and inset with top/left/bottom/right values.

Can you add padding to a border?

No, that's not possible. Padding, margin and border are all parts of elements, you can't give a border padding or a margin a border.


1 Answers

Easy peasy!

Padding, border and couple of box-shadows will do the trick.

img {    
    border-radius: 50%;
    padding: 3px;
    border: 1px solid #ddd;
    box-shadow: 0 0 0 7px #fff, 
                0 0 0 8px #ddd;
}

Fiddle

like image 174
Tigran Petrossian Avatar answered Nov 10 '22 20:11

Tigran Petrossian