I would like to vertical align a image in the center of a div.
For this I use this code:
<div id="cboxLoadedContent" style="width: 1024px; overflow: auto; height: 738px; vertical-align: middle;">
<img class="cboxPhoto" src="" style="cursor: pointer; float: none; width: 50%; vertical-align: middle;"></img>
</div>
JSFiddle: http://jsfiddle.net/3uk642wg/
How can I achieve that?
div#cboxLoadedContent {
....
display: table-cell;
text-align: center;
vertical-align: middle;
}
jsfiddle - http://jsfiddle.net/3uk642wg/1/
div#cboxLoadedContent {border: 1px solid #333; display: inline-block;text-align: center; display: table-cell;vertical-align: middle;} .cboxPhoto {vertical-align: middle;}
<div id="cboxLoadedContent" style="width: 1024px; overflow: auto; height: 738px; vertical-align: middle;"> <img class="cboxPhoto" src="https://www.google.com//images/srpr/logo11w.png" style="cursor: pointer; float: none; width: 50%; vertical-align: middle;"></img> </div>
If you are running this on modern browsers you can try this.
div#cboxLoadedContent {
border: 1px solid #333;
display: inline-block;
text-align: center;
}
.cboxPhoto {
position: relative;
top: 50%;
transform: translateY(-50%);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.