Online Forum To Support Coders With Technical Assistance - Read Write Execute

How to set a image vertically center align inside div

Ankit Agrawal
Ankit Agrawal
Published on January 9, 2016 · 1 min read
<div class="imgFrame">
    <img src="IMG SRC" />
</div>

<style>
.imgFrame {
    height: 100%;   
    width: 100%;
    text-align: center; 
}
.imgFrame:before,
.imgFrame {
    content: "";
    display: inline-block;
    height: 100%;
    vertical-align: middle;
}

.imgFrame img {
    vertical-align: middle;
    max-height: 100%;
    max-width: 100%;
}
</style>
Was this article helpful?
Ankit Agrawal

Ankit Agrawal

Author & Senior Engineer at CodeExecute

Writing practical engineering guides, debugging real-world bottlenecks, and creating free tools for developer productivity.

← Previous Article How to crop image in wordpress? Next Article → Custom file Upload in (spicifiec directory) WordPress