Jest t Rick to zrobić, nawet bez JavaScript. To, czego potrzebujemy, to znać wysokość rodziców i potrzebujemy jeszcze jednego tagu.
pierwsze, dodać SPAN-tag przed lub po IMG-Tag:
<div id="wrapper">
<div id="parent">
<span> </span><img src="path/i/got/from/database/image.png" />
</div>
</div>
z tym, następujące oświadczenie CSS wyrównuje obraz jako Poszukiwany
#parent {
height: 500px; /* This height is important for the following lines */
line-height: 500px; /* Text-content needs to get full height for the
'vertical-align'-attribute to work */
}
#parent span {
display: inline-block; /* Should work even for IE6/7 in this case */
height: 500px; /* Needed for IE */
width: 10px;
margin-right: -10px; /* Any element to the right is pushed to the left
offset of the SPAN-tag */
}
#parent img {
vertical-align: middle; /* Aligns the image in the middle of the SPAN-tag */
}
to powinno działać nawet dla IE6 i 7.
Edit:
Rozwiązanie ThinkingStiffs jest prostsze, a przez to lepsze. Po prostu nie działa w IE6.
rozwiązanie Purmous nie działa dla IE6 i 7, zobacz The display declaration
to działało pięknie, dzięki! – dreagan
Cóż, sprawi, że element nadrzędny będzie zachowywał się jak komórka tabeli. – user123444555621