Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inner border over images with CSS?

Tags:

css

image

border

I would like to add a white border over all my images in my content div using css. Images in the header and footer div areas should not be affected. how do I achieve this? See example image below. There are images of different sizes on the web pages.

See image:

Image with inner border

like image 528
user2369812 Avatar asked Oct 03 '13 13:10

user2369812


People also ask

How do you put a border around an image in CSS?

The border-image property allows you to specify an image to be used as the border around an element. The border-image property is a shorthand property for: border-image-source. border-image-slice.

How do I put an inside border in CSS?

Answer: Use the CSS box-shadow property If you want to place or draw the borders inside of a rectangular box there is a very simple solution — just use the CSS outline property instead of border and move it inside of the element's box using the CSS3 outline-offset property with a negative value.

What is outline-offset in CSS?

The outline-offset CSS property sets the amount of space between an outline and the edge or border of an element.


1 Answers

You can do this without having an extra element or pseudo element:

http://cssdeck.com/labs/t6nd0h9p

img {   outline: 1px solid white;   outline-offset: -4px; } 

IE9&10 do not support the outline-offset property, but otherwise support is good: http://caniuse.com/#search=outline

Alternate solution that doesn't require knowing the dimensions of the image:

http://cssdeck.com/labs/aajakwnl

<div class="ie-container"><img src="http://placekitten.com/200/200" /></div>  div.ie-container {   display: inline-block;   position: relative; }  div.ie-container:before {   display: block;   content: '';   position: absolute;   top: 4px;   right: 4px;   bottom: 4px;   left: 4px;   border: 1px solid white; }  img {   vertical-align: middle; /* optional */ } 
like image 122
cimmanon Avatar answered Oct 26 '22 00:10

cimmanon