I have centered a lot of stuff in my webdevelopment career, but I was wondering if there is a simple way to centering an image vertically without knowing the image\'s dimens
If your design doesn't allow you to make parent
inline (if it does, use Purmou's solution, it's better), you can set line-height
on parent
equal to its height
and vertical-align: middle;
on your img
.
Demo: http://jsfiddle.net/ThinkingStiff/YRGBk/
HTML:
CSS:
img {
vertical-align: middle;
}
#parent {
height:400px;
border:1px solid black;
line-height: 400px;
}
Output: