leonnk
Programmer
- May 1, 2009
- 11
I am trying to vertically align my img's inside a div.
I have a series of portrait and landscape images which are generated through a javascript gallery (I add them as their full size images to the html and the script resizes them as thumbnails and creates the fullsize image in a specified div elsewhere on the page).
So because of that, I can't use relative positioning or padding.
But here's a simple example:
CSS:
.center
{
width:700px;
height:700px;
background-color:#00F;
}
HTML:
<div class="center">
<img width="676px" height="485px" src="photo.jpg" />
</div>
So on this I have tried...
Vertical-align:middle;
---
.center
{line-height:700px;}
---
.center
{position:absolute;
top:50%;
left:50%;
margin-left:-50%;
margin-top:-50%;
}
Are there any other css based techniques?
Thanks
I have a series of portrait and landscape images which are generated through a javascript gallery (I add them as their full size images to the html and the script resizes them as thumbnails and creates the fullsize image in a specified div elsewhere on the page).
So because of that, I can't use relative positioning or padding.
But here's a simple example:
CSS:
.center
{
width:700px;
height:700px;
background-color:#00F;
}
HTML:
<div class="center">
<img width="676px" height="485px" src="photo.jpg" />
</div>
So on this I have tried...
Vertical-align:middle;
---
.center
{line-height:700px;}
---
.center
{position:absolute;
top:50%;
left:50%;
margin-left:-50%;
margin-top:-50%;
}
Are there any other css based techniques?
Thanks