views:

115

answers:

3

I'm trying to figure out the css to display an image with a 1px black border then a 9px white border around that. Is there an easy way to do this?

The div around image answer almost works, but I still have big gaps on either side of my image (outside of the 1px border and inside of the 9px border). It seems like the div tag is stretching to fit the entire window for some reason.

I ended up using the padding/border in img styling option.

+2  A: 
<div style="border: 9px solid white;">
    <img src="foo.png" style="border: 1px solid black;"/>
</div>
Can Berk Güder
For some reason the div border has a big gap between it and the img border, can't figure out why
Luke
Try adding padding: 0 to style attribute to remove that gap
victor hugo
Check out this SO question regarding the spacing: http://stackoverflow.com/questions/948145/unwanted-spacing-below-images-in-xhtml-1-0-strict
Ólafur Waage
The padding trick didn't work. That other question fixed my 1px space below the image, but I still have big gaps on either side heh :)
Luke
+2  A: 

You can't assign multiple borders with pure CSS, you're gonna have to put a div around it. Div because it's block-level.

Something like

<div class="img-border"><img class="img" src="..." /></div>

and the CSS would be:

.img{
  border: solid 1px black;
}

.img-border{
  border: solid 9px white;
}

Using classes, you don't have to re-type the inline CSS for every single image. That's what I've come up with in 30 seconds. Hope it helps.

WebDevHobo
+4  A: 

On img, set the background to black and add 1px of padding then the border can be the 9px of white.

img { background-color:#000; padding:1px; border:9px solid #fff; }

This will give a double border as long as you don't have transparent images.

Emily