How to vertically align center to an image inside div using CSS?


I have an image inside div like this

<div class="MainDiv">
   <img src="/Content/Images/116.gif" alt="Comcast: West Region">
</div>

So, I would like to know How can I vertically align center to an image inside div using CSS?


Asked by:- Vinnu
1
: 2621 At:- 9/27/2017 8:06:14 AM
CSS HTML vertical-align-middle image alignment







1 Answers
profileImage Answered by:- vikas_jk

You can align image centrally inside a div using this code

.Main{
        display: flex;      
        align-items: center;
    }

.Main img {
/* change it accordingly */
  max-height: 25px;
 }


  /* Styling stuff not needed for demo*/
    .Main{
        height: 24px;
    }

You can keep your HTML as it just add the above CSS in your stylesheet it should work

1
At:- 9/28/2017 8:26:05 AM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use