views:

34

answers:

2

Hi - I'm trying to place a nice border around an image that's 250x250, using only html and css. The markup is this:

<div id="img-container"><img src="pic.jpg" border="0"/></div>

And the css is:

#img-container {
    height: 225px;
    width: 225px;
    padding: 3px;
    border: 1px solid black;
    z-index: 10;
    position: relative;
    overflow: hidden;
    border-radius: 10px;
}

#img-container img {
    z-index: 5;
}

Basically, I want the div container to clip the picture's edges that exceed its boundaries. This will achieve the rounded edges effect using the border-radius property (-moz-border-radius, -webkit-border-radius, etc) - if it actually works or could even be done. Looking for tips and tricks on this. Thanks.

And, yes, I'm obviously not a web designer :)

+1  A: 

as far as I understood your question, deleting the

#img-container img {
    z-index: 5;
}

part should do the trick.

Or you could use the image as a background image:

#img-container {
    ...
    background: url(pic.jpg) no-repeat top left;
}
Mannaz
+2  A: 

Yes it's possible, but you should set the image as the div background using CSS:

#img-container {
    height: 225px;
    width: 225px;
    padding: 3px;
    border: 1px solid black;
    background-image: url('pic.jpg');
    border-radius: 10px;
}

This is necessary, otherwise you will get horrible white borders around the image (tested in Google Chrome).

James
you're right, using it as bg worked great - thanks!
sa125