PDA

View Full Version : Centering an image in CSS



Davehead
July 12th, 2005, 09:41 AM
Hi guys,
I am in a bit of a pickle here. I have been trying to center an image in a div, but cannot seem to do it.
I have searched and found this (http://www.kirupa.com/forum/showthread.php?t=85500&highlight=center+image) thread, but it hasnt helped.

Basically I have:

#picture_nest
{
padding: 0px;
display: block;
float: left;
width: 143px;
margin-left: 0px;
}
.picture {
text-align: center;
}

and I have it as so:

<div id="picture_nest"><span class="picture"><img src="blah.jpg"></span></div>

But obvioulsy "text-align: center;" is not working.

Any ideas ?

Cheers,
D

simplistik
July 12th, 2005, 10:11 AM
body {
background-color: #151515;
padding: 0px;
text-align: center;
}
#wrapper {
text-align: center;
position: absolute;
top: 50%;
left: 0px;
width: 100%;
height: 1px;
display: block
z-index:2;
}
#img {
margin-left: -115px;
position: absolute;
top: -101px;
left: 50%;
height: 202px;
width: 230px;
visibility: visible
z-index:2;
}

came out of another post that we answered a while back