Align image in center and middle within div












257















I have following div



<div id="over" style="position:absolute; width:100%; height:100%>
<img src="img.png">
</div>


How to align the image so as to be located in the middle and center of div ?










share|improve this question




















  • 10





    Duplicate asked 2 minutes ago: CSS: image middle

    – Pekka 웃
    Feb 3 '11 at 15:43








  • 1





    Similar topic here: stackoverflow.com/questions/18516317/…

    – Hashem Qolami
    Jan 20 '14 at 23:38











  • Consider selecting one answer as correct.

    – McSonk
    Apr 20 '17 at 14:59











  • Possible duplicate of How to position image in the center/middle both vertically and horizontally

    – gbjbaanb
    Oct 3 '17 at 15:06
















257















I have following div



<div id="over" style="position:absolute; width:100%; height:100%>
<img src="img.png">
</div>


How to align the image so as to be located in the middle and center of div ?










share|improve this question




















  • 10





    Duplicate asked 2 minutes ago: CSS: image middle

    – Pekka 웃
    Feb 3 '11 at 15:43








  • 1





    Similar topic here: stackoverflow.com/questions/18516317/…

    – Hashem Qolami
    Jan 20 '14 at 23:38











  • Consider selecting one answer as correct.

    – McSonk
    Apr 20 '17 at 14:59











  • Possible duplicate of How to position image in the center/middle both vertically and horizontally

    – gbjbaanb
    Oct 3 '17 at 15:06














257












257








257


72






I have following div



<div id="over" style="position:absolute; width:100%; height:100%>
<img src="img.png">
</div>


How to align the image so as to be located in the middle and center of div ?










share|improve this question
















I have following div



<div id="over" style="position:absolute; width:100%; height:100%>
<img src="img.png">
</div>


How to align the image so as to be located in the middle and center of div ?







html css






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 19 '14 at 0:11









simple_human

9,09344667




9,09344667










asked Feb 3 '11 at 15:42









Dro1n2Dro1n2

1,3352117




1,3352117








  • 10





    Duplicate asked 2 minutes ago: CSS: image middle

    – Pekka 웃
    Feb 3 '11 at 15:43








  • 1





    Similar topic here: stackoverflow.com/questions/18516317/…

    – Hashem Qolami
    Jan 20 '14 at 23:38











  • Consider selecting one answer as correct.

    – McSonk
    Apr 20 '17 at 14:59











  • Possible duplicate of How to position image in the center/middle both vertically and horizontally

    – gbjbaanb
    Oct 3 '17 at 15:06














  • 10





    Duplicate asked 2 minutes ago: CSS: image middle

    – Pekka 웃
    Feb 3 '11 at 15:43








  • 1





    Similar topic here: stackoverflow.com/questions/18516317/…

    – Hashem Qolami
    Jan 20 '14 at 23:38











  • Consider selecting one answer as correct.

    – McSonk
    Apr 20 '17 at 14:59











  • Possible duplicate of How to position image in the center/middle both vertically and horizontally

    – gbjbaanb
    Oct 3 '17 at 15:06








10




10





Duplicate asked 2 minutes ago: CSS: image middle

– Pekka 웃
Feb 3 '11 at 15:43







Duplicate asked 2 minutes ago: CSS: image middle

– Pekka 웃
Feb 3 '11 at 15:43






1




1





Similar topic here: stackoverflow.com/questions/18516317/…

– Hashem Qolami
Jan 20 '14 at 23:38





Similar topic here: stackoverflow.com/questions/18516317/…

– Hashem Qolami
Jan 20 '14 at 23:38













Consider selecting one answer as correct.

– McSonk
Apr 20 '17 at 14:59





Consider selecting one answer as correct.

– McSonk
Apr 20 '17 at 14:59













Possible duplicate of How to position image in the center/middle both vertically and horizontally

– gbjbaanb
Oct 3 '17 at 15:06





Possible duplicate of How to position image in the center/middle both vertically and horizontally

– gbjbaanb
Oct 3 '17 at 15:06












29 Answers
29






active

oldest

votes


















365














JSFiddle






body {
margin: 0;
}

#over img {
margin-left: auto;
margin-right: auto;
display: block;
}

<div id="over" style="position:absolute; width:100%; height:100%">
<img src="http://www.garcard.com/images/garcard_symbol.png">
</div>








share|improve this answer





















  • 8





    doesnt work, this will work if the element is not floating on any direction...

    – vikas devde
    Apr 21 '13 at 12:26






  • 4





    display: block; was my pitfall. TnX

    – Ujjwal Singh
    May 9 '13 at 8:23






  • 2





    Following doesn't work. What's the mistake i am doing. <html> <head> <style> #over img { display: block; margin-left: auto; margin-right: auto; } </style> </head> <body> <div id="over" style="position:absolute; width:100%; height:100%"> <img src="img8a.flixcart.com/image/tablet/f/k/t/…"> </div> </body> </html>

    – nizam.sp
    Oct 21 '13 at 11:00








  • 8





    This doesn't align vertically

    – alpadev
    May 11 '17 at 14:32






  • 13





    How can an answer that do not attend the question get more than 300 votes???

    – Rodrigo
    Jun 9 '17 at 13:13



















147














<div style="display:table-cell; vertical-align:middle; text-align:center">
<img src="img.png">
</div>





share|improve this answer





















  • 4





    top answer, very helpful!

    – Ilian Andreev
    Jun 2 '13 at 19:58






  • 1





    Very short and easy solution, but it appears to only be working with a fixed, non-percentage width and height. It does work with floats though so +1 for that. — jsfiddle.net/2s2nY/2

    – magnetronnie
    May 26 '14 at 10:10






  • 1





    but this is only doing the vertical-align but not the horizontal right?

    – V-SHY
    Mar 25 '15 at 3:38






  • 1





    It won't work if image's width larger than div's width.

    – Davuz
    May 26 '15 at 7:02






  • 4





    If we remove display:table-cell; it works perfactly.

    – Ahesanali Momin
    May 18 '17 at 7:39



















87














Seems to me that you also wanted that image to be vertically centered within the container. (I didn't see any answer that provided that)



Working Fiddle:




  1. Pure CSS solution

  2. Not breaking the document flow (no floats or absolute positioning)

  3. Cross browser compatibility (even IE6)

  4. Completely responsive.


HTML



<div id="over">
<span class="Centerer"></span>
<img class="Centered" src="http://th07.deviantart.net/fs71/200H/f/2013/236/d/b/bw_avlonas_a5_beach_isles_wallpaper_image_by_lemnosexplorer-d6jh3i7.jpg" />
</div>


CSS



*
{
padding: 0;
margin: 0;
}
#over
{
position:absolute;
width:100%;
height:100%;
text-align: center; /*handles the horizontal centering*/
}
/*handles the vertical centering*/
.Centerer
{
display: inline-block;
height: 100%;
vertical-align: middle;
}
.Centered
{
display: inline-block;
vertical-align: middle;
}


Note: this solution is good to align any element within any element.
for IE7, when applying the .Centered class on block elements, you will have to use another trick to get the inline-block working. (that because IE6/IE7 dont play well with inline-block on block elements)






share|improve this answer





















  • 10





    Only this one is working (vertical & horizontal)

    – Bartek Kosa
    Nov 13 '13 at 13:01






  • 1





    This is superb...Magic!!! Worked awesomly well! Thanks so much for this...

    – Nitin Bansal
    Jul 1 '14 at 10:55






  • 2





    excellent.. this should the answer to this question.

    – user3790264
    Sep 30 '14 at 10:59






  • 2





    Should be the accepted answer +1

    – Lehan Coetzee
    Feb 2 '16 at 11:17






  • 2





    Works perfectly!

    – wotaskd
    Jun 8 '16 at 14:28



















86














This can also be done using the Flexbox layout:



STATIC SIZE




.parent {
display: flex;
height: 300px; /* Or whatever */
background-color: #000;
}

.child {
width: 100px; /* Or whatever */
height: 100px; /* Or whatever */
margin: auto; /* Magic! */
}

<div class="parent">
<img class="child" src="https://i.vimeocdn.com/portrait/58832_300x300"/>
</div>





DYNAMIC SIZE




html, body {
width: 100%;
height: 100%;
display: flex;
background-color: #999;
}

* {
margin: 0;
padding: 0;
}

.parent {
margin: auto;
background-color: #000;
display: flex;
height: 80%;
width: 80%;
}

.child {
margin: auto; /* Magic! */
max-width: 100%;
max-height: 100%;
}

<div class="parent">
<img class="child" src="https://i.vimeocdn.com/portrait/58832_300x300"/>
</div>





I found the example in this article, which does a great job explaining the how to use layout.






share|improve this answer


























  • flex is state of the art - just works without tricks

    – Bernhard Zürn
    Jan 17 '17 at 20:02











  • In the Static Size, there's no need for width and height for the child (at least in my version of Firefox).

    – Rodrigo
    Jun 9 '17 at 13:23



















59














img.centered {
display: block;
margin: auto auto;
}





share|improve this answer





















  • 1





    this is very similar to this answer

    – simple_human
    Jul 19 '14 at 0:29



















27














#over {position:relative; text-align:center; 
width:100%; height:100%; background:#CCC;}

#over img{
position: absolute;
margin: auto;
top: 0;
left: 0;
right: 0;
bottom: 0;
}





share|improve this answer


























  • Best solution that actually works.

    – Burjua
    Jun 15 '17 at 13:10











  • This is the right answer, that actually centers both vertically and horizontally.

    – Alexander Kim
    Jun 7 '18 at 8:44











  • Best answer so far.

    – kiran puppala
    Jan 31 at 9:02



















25














You can do this easily by using display:flex css property



#over {
height: 100%;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}





share|improve this answer

































    11














    I still had some issues with other solution presented here. Finally this worked best for me:



    <div class="parent">
    <img class="child" src="image.png"/>
    </div>


    css3:



    .child {
    display: block;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    -webkit-transform: translate(-50%, -50%); /* Safari and Chrome */
    -moz-transform: translate(-50%, -50%); /* Firefox */
    -ms-transform: translate(-50%, -50%); /* IE 9 */
    -o-transform: translate(-50%, -50%); /* Opera */
    // I suppose you may like those too:
    // max-width: 80%;
    // max-height: 80%;
    }


    You can read more about that approach at this page.






    share|improve this answer
























    • I had to also add parent css but your code worked perfectly! position: relative; width: 100%; float: left; overflow: hidden; min-height: 189px;

      – user2593040
      Dec 9 '16 at 9:12



















    10














    Basically, setting right and left margin to auto will cause the image to center align.



    <div id="over" style="position:absolute; width:100%; height:100%>
    <img src="img.png" style="display: block; margin: 0 auto;">
    </div>





    share|improve this answer

































      8














      This would be a simpler approach



      #over > img{
      display: block;
      margin:0 auto;
      }





      share|improve this answer

































        6














        setting the img to display:inline-block while having set the superior div to text-align:center will do the job too



        EDIT: to those folks who are playing with display:inline-block >>> don't forget that e.g. two divs like



        <div>Div1 content</div>NOSPACEHERE<div>Div2 content</div>


        really have no spaces between them (as seen here).



        Just basic to avoid these (inline block inherent) gaps between them. These gaps can be seen between every two words I'm writing right now! :-) So .. hope this helps some of you.






        share|improve this answer

































          6














          SIMPLE. 2018. FlexBox. To Check Browser Support - Can I Use


          Minimal Solution:



          div#over { 
          display: flex;
          justify-content: center;
          align-items: center;
          }





          To get the widest browser support possible:



          div#over { 
          display: -webkit-flex;
          display: -ms-flex;
          display: flex;
          justify-content: center;
          -ms-align-items: center;
          align-items: center;
          }





          share|improve this answer

































            5














            I've tried many approaches but only this one works for multiple inline elements inside a container div. Here is code to align everything in div at middle.



            CSS



            .divContainer
            {
            vertical-align: middle;
            text-align: center; <!-- If you want horizontal center alignment -->
            }
            .divContainer > *
            {
            vertical-align: middle;
            }


            HTML



            <div class="divContainer">
            <span>Middle Text</span>
            <img src="test.png"/>
            </div>


            Sample code is here: https://jsfiddle.net/yogendrasinh/2vq0c68m/






            share|improve this answer































              5














              CSS File



              .over {
              display : block;
              margin : 0px auto;





              share|improve this answer

































                3














                Try this minimal code:



                <div class="outer">
                <img src="image.png"/>
                </div>


                And CSS:



                .outer{
                text-align: center;
                }
                .outer img{
                display: inline-block;
                }





                share|improve this answer

































                  2














                  many answer suggests to use margin:0 auto but this works only when the element you trying to make centered is not floating on left or right, that is float css attribute isn't set. In order to do this apply display attribute to table-cell and then apply margin of left and right to auto so your style will look like style="display:table-cell;margin:0 auto;"






                  share|improve this answer































                    2














                        <div>
                    <p style="text-align:center; margin-top:0px; margin-bottom:0px; padding:0px;">
                    <img src="image.jpg" alt="image"/>
                    </p>
                    </div>





                    share|improve this answer































                      2














                      HTML:



                      <div id="over">
                      <img src="img.png">
                      </div>


                      CSS:



                      #over {
                      text-align: center;
                      }

                      #over img {
                      vertical-align: middle;
                      }





                      share|improve this answer


























                      • It's best if you add some commentary and not just toss code out there.

                        – Parkash Kumar
                        Oct 26 '15 at 10:43



















                      2














                      For center horizontally Just put



                      #over img {
                      display: block;
                      margin: 0 auto;
                      clear:both;
                      }


                      Another method:



                      #over img {
                      display: inline-block;
                      text-align: center;
                      }


                      For center vertically Just put:



                         #over img {

                      vertical-align: middle;
                      }





                      share|improve this answer

































                        2














                        This worked for me:



                        #image-id {
                        position: absolute;
                        top: 0; left: 0; right: 0; bottom: 0;
                        width: auto;
                        margin: 0 auto;
                        }





                        share|improve this answer































                          2














                          Well, we are in 2016... why not use flexbox?
                          It's also responsive. Enjoy.




                          #over{
                          display:flex;
                          align-items:center;
                          justify-content:center;
                          }

                          <div id="over">
                          <img src="http://www.garcard.com/images/garcard_symbol.png">
                          </div>








                          share|improve this answer



















                          • 1





                            Love css3! Thank you. However, its good to note that this will only work in modern browsers (except IE). All other browsers will have no effect.

                            – Neel
                            Jan 9 '17 at 16:44





















                          2














                          this did the trick for me.



                          <div class="CenterImage">
                          <asp:Image ID="BrandImage" runat="server" />
                          </div>


                          'Note: do not have a css class assocaited to 'BrandImage' in this case



                          CSS:



                          .CenterImage {
                          position:absolute;
                          width:100%;
                          height:100%
                          }

                          .CenterImage img {
                          margin: 0 auto;
                          display: block;
                          }





                          share|improve this answer































                            1














                            Use positioning. The following worked for me...



                            With zoom to the center of the image (image fills the div):



                            div{
                            display:block;
                            overflow:hidden;
                            width: 70px;
                            height: 70px;
                            position: relative;
                            }
                            div img{
                            min-width: 70px;
                            min-height: 70px;
                            max-width: 250%;
                            max-height: 250%;
                            top: -50%;
                            left: -50%;
                            bottom: -50%;
                            right: -50%;
                            position: absolute;
                            }


                            Without zoom to the center of the image (image does not fill the div):



                               div{
                            display:block;
                            overflow:hidden;
                            width: 100px;
                            height: 100px;
                            position: relative;
                            }
                            div img{
                            width: 70px;
                            height: 70px;
                            top: 50%;
                            left: 50%;
                            bottom: 50%;
                            right: 50%;
                            position: absolute;
                            }





                            share|improve this answer































                              0














                              You can take a look on this solution:



                              Centering horizontally and vertically an image in a box



                              <style type="text/css">
                              .wraptocenter {
                              display: table-cell;
                              text-align: center;
                              vertical-align: middle;
                              width: ...;
                              height: ...;
                              }
                              .wraptocenter * {
                              vertical-align: middle;
                              }
                              .wraptocenter {
                              display: block;
                              }
                              .wraptocenter span {
                              display: inline-block;
                              height: 100%;
                              width: 1px;
                              }
                              </style>
                              <!--[if lt IE 8]-->
                              <style>
                              .wraptocenter span {
                              display: inline-block;
                              height: 100%;
                              }
                              </style>
                              <!--[endif]-->

                              <div class="wraptocenter"><span></span><img src="..." alt="..."></div>





                              share|improve this answer

































                                0














                                A simple way would be creating separate styles for both the div and the image and then position them independently. Say if I want to set my image position to 50%, then I would have code which looks like the following....






                                #over{
                                position:absolute;
                                width:100%;
                                height:100%;
                                }
                                #img{
                                position:absolute;
                                left:50%;
                                right:50%;
                                }

                                <div id="over">
                                <img src="img.png" id="img">
                                </div>








                                share|improve this answer


























                                • Just tell me if it works with all kinds of browsers, even though this is a basic thing that every browser must support (otherwise don't call it a browser)

                                  – KSJ10
                                  Nov 21 '16 at 17:00



















                                0














                                #over {
                                display: table-cell;
                                vertical-align: middle;
                                text-align: center;
                                height: 100px;
                                }


                                Modify height value for your need.






                                share|improve this answer































                                  0














                                  This should work.



                                  IMPORTANT FOR TEST: To Run code snippet click left button RUN code snippet, then right link Full page






                                  #fader{
                                  position:fixed;z-index: 10;
                                  top:0;right:0;bottom:0;left:0;
                                  opacity: 0.8;background: black;
                                  width:100%;height:100%;
                                  text-align: center;
                                  }
                                  .faders{display:inline-block;height:100%;vertical-align:middle;}
                                  .faderi{display:inline-block;vertical-align:middle;}

                                  <div id="fader">
                                  <span class="faders"></span>
                                  <img class="faderi" src="https://i.stack.imgur.com/qHF2K.png" />
                                  </div>








                                  share|improve this answer

































                                    0














                                    Use bootstraps align-items and justify-content. See example below:



                                    <div class="well" style="align-items:center;justify-content:center;">
                                    <img src="img_source" height="50px" width="50px"/>
                                    </div>





                                    share|improve this answer































                                      0














                                      I add some more properties to the CSS. Like so:



                                      div#over {
                                      width: 100%;
                                      height: 100%;
                                      display: flex;
                                      justify-content: center;
                                      align-items: center;
                                      -ms-align-items: center;
                                      display: -webkit-flex;
                                      display: -ms-flex;
                                      display: flex;
                                      }





                                      share|improve this answer






















                                        protected by Tushar Gupta Oct 15 '14 at 17:37



                                        Thank you for your interest in this question.
                                        Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                        Would you like to answer one of these unanswered questions instead?














                                        29 Answers
                                        29






                                        active

                                        oldest

                                        votes








                                        29 Answers
                                        29






                                        active

                                        oldest

                                        votes









                                        active

                                        oldest

                                        votes






                                        active

                                        oldest

                                        votes









                                        365














                                        JSFiddle






                                        body {
                                        margin: 0;
                                        }

                                        #over img {
                                        margin-left: auto;
                                        margin-right: auto;
                                        display: block;
                                        }

                                        <div id="over" style="position:absolute; width:100%; height:100%">
                                        <img src="http://www.garcard.com/images/garcard_symbol.png">
                                        </div>








                                        share|improve this answer





















                                        • 8





                                          doesnt work, this will work if the element is not floating on any direction...

                                          – vikas devde
                                          Apr 21 '13 at 12:26






                                        • 4





                                          display: block; was my pitfall. TnX

                                          – Ujjwal Singh
                                          May 9 '13 at 8:23






                                        • 2





                                          Following doesn't work. What's the mistake i am doing. <html> <head> <style> #over img { display: block; margin-left: auto; margin-right: auto; } </style> </head> <body> <div id="over" style="position:absolute; width:100%; height:100%"> <img src="img8a.flixcart.com/image/tablet/f/k/t/…"> </div> </body> </html>

                                          – nizam.sp
                                          Oct 21 '13 at 11:00








                                        • 8





                                          This doesn't align vertically

                                          – alpadev
                                          May 11 '17 at 14:32






                                        • 13





                                          How can an answer that do not attend the question get more than 300 votes???

                                          – Rodrigo
                                          Jun 9 '17 at 13:13
















                                        365














                                        JSFiddle






                                        body {
                                        margin: 0;
                                        }

                                        #over img {
                                        margin-left: auto;
                                        margin-right: auto;
                                        display: block;
                                        }

                                        <div id="over" style="position:absolute; width:100%; height:100%">
                                        <img src="http://www.garcard.com/images/garcard_symbol.png">
                                        </div>








                                        share|improve this answer





















                                        • 8





                                          doesnt work, this will work if the element is not floating on any direction...

                                          – vikas devde
                                          Apr 21 '13 at 12:26






                                        • 4





                                          display: block; was my pitfall. TnX

                                          – Ujjwal Singh
                                          May 9 '13 at 8:23






                                        • 2





                                          Following doesn't work. What's the mistake i am doing. <html> <head> <style> #over img { display: block; margin-left: auto; margin-right: auto; } </style> </head> <body> <div id="over" style="position:absolute; width:100%; height:100%"> <img src="img8a.flixcart.com/image/tablet/f/k/t/…"> </div> </body> </html>

                                          – nizam.sp
                                          Oct 21 '13 at 11:00








                                        • 8





                                          This doesn't align vertically

                                          – alpadev
                                          May 11 '17 at 14:32






                                        • 13





                                          How can an answer that do not attend the question get more than 300 votes???

                                          – Rodrigo
                                          Jun 9 '17 at 13:13














                                        365












                                        365








                                        365







                                        JSFiddle






                                        body {
                                        margin: 0;
                                        }

                                        #over img {
                                        margin-left: auto;
                                        margin-right: auto;
                                        display: block;
                                        }

                                        <div id="over" style="position:absolute; width:100%; height:100%">
                                        <img src="http://www.garcard.com/images/garcard_symbol.png">
                                        </div>








                                        share|improve this answer















                                        JSFiddle






                                        body {
                                        margin: 0;
                                        }

                                        #over img {
                                        margin-left: auto;
                                        margin-right: auto;
                                        display: block;
                                        }

                                        <div id="over" style="position:absolute; width:100%; height:100%">
                                        <img src="http://www.garcard.com/images/garcard_symbol.png">
                                        </div>








                                        body {
                                        margin: 0;
                                        }

                                        #over img {
                                        margin-left: auto;
                                        margin-right: auto;
                                        display: block;
                                        }

                                        <div id="over" style="position:absolute; width:100%; height:100%">
                                        <img src="http://www.garcard.com/images/garcard_symbol.png">
                                        </div>





                                        body {
                                        margin: 0;
                                        }

                                        #over img {
                                        margin-left: auto;
                                        margin-right: auto;
                                        display: block;
                                        }

                                        <div id="over" style="position:absolute; width:100%; height:100%">
                                        <img src="http://www.garcard.com/images/garcard_symbol.png">
                                        </div>






                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Jan 21 '17 at 8:41









                                        H. Pauwelyn

                                        5,931184988




                                        5,931184988










                                        answered Sep 5 '12 at 13:10









                                        Gurpreet SinghGurpreet Singh

                                        3,9881910




                                        3,9881910








                                        • 8





                                          doesnt work, this will work if the element is not floating on any direction...

                                          – vikas devde
                                          Apr 21 '13 at 12:26






                                        • 4





                                          display: block; was my pitfall. TnX

                                          – Ujjwal Singh
                                          May 9 '13 at 8:23






                                        • 2





                                          Following doesn't work. What's the mistake i am doing. <html> <head> <style> #over img { display: block; margin-left: auto; margin-right: auto; } </style> </head> <body> <div id="over" style="position:absolute; width:100%; height:100%"> <img src="img8a.flixcart.com/image/tablet/f/k/t/…"> </div> </body> </html>

                                          – nizam.sp
                                          Oct 21 '13 at 11:00








                                        • 8





                                          This doesn't align vertically

                                          – alpadev
                                          May 11 '17 at 14:32






                                        • 13





                                          How can an answer that do not attend the question get more than 300 votes???

                                          – Rodrigo
                                          Jun 9 '17 at 13:13














                                        • 8





                                          doesnt work, this will work if the element is not floating on any direction...

                                          – vikas devde
                                          Apr 21 '13 at 12:26






                                        • 4





                                          display: block; was my pitfall. TnX

                                          – Ujjwal Singh
                                          May 9 '13 at 8:23






                                        • 2





                                          Following doesn't work. What's the mistake i am doing. <html> <head> <style> #over img { display: block; margin-left: auto; margin-right: auto; } </style> </head> <body> <div id="over" style="position:absolute; width:100%; height:100%"> <img src="img8a.flixcart.com/image/tablet/f/k/t/…"> </div> </body> </html>

                                          – nizam.sp
                                          Oct 21 '13 at 11:00








                                        • 8





                                          This doesn't align vertically

                                          – alpadev
                                          May 11 '17 at 14:32






                                        • 13





                                          How can an answer that do not attend the question get more than 300 votes???

                                          – Rodrigo
                                          Jun 9 '17 at 13:13








                                        8




                                        8





                                        doesnt work, this will work if the element is not floating on any direction...

                                        – vikas devde
                                        Apr 21 '13 at 12:26





                                        doesnt work, this will work if the element is not floating on any direction...

                                        – vikas devde
                                        Apr 21 '13 at 12:26




                                        4




                                        4





                                        display: block; was my pitfall. TnX

                                        – Ujjwal Singh
                                        May 9 '13 at 8:23





                                        display: block; was my pitfall. TnX

                                        – Ujjwal Singh
                                        May 9 '13 at 8:23




                                        2




                                        2





                                        Following doesn't work. What's the mistake i am doing. <html> <head> <style> #over img { display: block; margin-left: auto; margin-right: auto; } </style> </head> <body> <div id="over" style="position:absolute; width:100%; height:100%"> <img src="img8a.flixcart.com/image/tablet/f/k/t/…"> </div> </body> </html>

                                        – nizam.sp
                                        Oct 21 '13 at 11:00







                                        Following doesn't work. What's the mistake i am doing. <html> <head> <style> #over img { display: block; margin-left: auto; margin-right: auto; } </style> </head> <body> <div id="over" style="position:absolute; width:100%; height:100%"> <img src="img8a.flixcart.com/image/tablet/f/k/t/…"> </div> </body> </html>

                                        – nizam.sp
                                        Oct 21 '13 at 11:00






                                        8




                                        8





                                        This doesn't align vertically

                                        – alpadev
                                        May 11 '17 at 14:32





                                        This doesn't align vertically

                                        – alpadev
                                        May 11 '17 at 14:32




                                        13




                                        13





                                        How can an answer that do not attend the question get more than 300 votes???

                                        – Rodrigo
                                        Jun 9 '17 at 13:13





                                        How can an answer that do not attend the question get more than 300 votes???

                                        – Rodrigo
                                        Jun 9 '17 at 13:13













                                        147














                                        <div style="display:table-cell; vertical-align:middle; text-align:center">
                                        <img src="img.png">
                                        </div>





                                        share|improve this answer





















                                        • 4





                                          top answer, very helpful!

                                          – Ilian Andreev
                                          Jun 2 '13 at 19:58






                                        • 1





                                          Very short and easy solution, but it appears to only be working with a fixed, non-percentage width and height. It does work with floats though so +1 for that. — jsfiddle.net/2s2nY/2

                                          – magnetronnie
                                          May 26 '14 at 10:10






                                        • 1





                                          but this is only doing the vertical-align but not the horizontal right?

                                          – V-SHY
                                          Mar 25 '15 at 3:38






                                        • 1





                                          It won't work if image's width larger than div's width.

                                          – Davuz
                                          May 26 '15 at 7:02






                                        • 4





                                          If we remove display:table-cell; it works perfactly.

                                          – Ahesanali Momin
                                          May 18 '17 at 7:39
















                                        147














                                        <div style="display:table-cell; vertical-align:middle; text-align:center">
                                        <img src="img.png">
                                        </div>





                                        share|improve this answer





















                                        • 4





                                          top answer, very helpful!

                                          – Ilian Andreev
                                          Jun 2 '13 at 19:58






                                        • 1





                                          Very short and easy solution, but it appears to only be working with a fixed, non-percentage width and height. It does work with floats though so +1 for that. — jsfiddle.net/2s2nY/2

                                          – magnetronnie
                                          May 26 '14 at 10:10






                                        • 1





                                          but this is only doing the vertical-align but not the horizontal right?

                                          – V-SHY
                                          Mar 25 '15 at 3:38






                                        • 1





                                          It won't work if image's width larger than div's width.

                                          – Davuz
                                          May 26 '15 at 7:02






                                        • 4





                                          If we remove display:table-cell; it works perfactly.

                                          – Ahesanali Momin
                                          May 18 '17 at 7:39














                                        147












                                        147








                                        147







                                        <div style="display:table-cell; vertical-align:middle; text-align:center">
                                        <img src="img.png">
                                        </div>





                                        share|improve this answer















                                        <div style="display:table-cell; vertical-align:middle; text-align:center">
                                        <img src="img.png">
                                        </div>






                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Feb 3 '11 at 15:53

























                                        answered Feb 3 '11 at 15:48









                                        John K.John K.

                                        4,60711620




                                        4,60711620








                                        • 4





                                          top answer, very helpful!

                                          – Ilian Andreev
                                          Jun 2 '13 at 19:58






                                        • 1





                                          Very short and easy solution, but it appears to only be working with a fixed, non-percentage width and height. It does work with floats though so +1 for that. — jsfiddle.net/2s2nY/2

                                          – magnetronnie
                                          May 26 '14 at 10:10






                                        • 1





                                          but this is only doing the vertical-align but not the horizontal right?

                                          – V-SHY
                                          Mar 25 '15 at 3:38






                                        • 1





                                          It won't work if image's width larger than div's width.

                                          – Davuz
                                          May 26 '15 at 7:02






                                        • 4





                                          If we remove display:table-cell; it works perfactly.

                                          – Ahesanali Momin
                                          May 18 '17 at 7:39














                                        • 4





                                          top answer, very helpful!

                                          – Ilian Andreev
                                          Jun 2 '13 at 19:58






                                        • 1





                                          Very short and easy solution, but it appears to only be working with a fixed, non-percentage width and height. It does work with floats though so +1 for that. — jsfiddle.net/2s2nY/2

                                          – magnetronnie
                                          May 26 '14 at 10:10






                                        • 1





                                          but this is only doing the vertical-align but not the horizontal right?

                                          – V-SHY
                                          Mar 25 '15 at 3:38






                                        • 1





                                          It won't work if image's width larger than div's width.

                                          – Davuz
                                          May 26 '15 at 7:02






                                        • 4





                                          If we remove display:table-cell; it works perfactly.

                                          – Ahesanali Momin
                                          May 18 '17 at 7:39








                                        4




                                        4





                                        top answer, very helpful!

                                        – Ilian Andreev
                                        Jun 2 '13 at 19:58





                                        top answer, very helpful!

                                        – Ilian Andreev
                                        Jun 2 '13 at 19:58




                                        1




                                        1





                                        Very short and easy solution, but it appears to only be working with a fixed, non-percentage width and height. It does work with floats though so +1 for that. — jsfiddle.net/2s2nY/2

                                        – magnetronnie
                                        May 26 '14 at 10:10





                                        Very short and easy solution, but it appears to only be working with a fixed, non-percentage width and height. It does work with floats though so +1 for that. — jsfiddle.net/2s2nY/2

                                        – magnetronnie
                                        May 26 '14 at 10:10




                                        1




                                        1





                                        but this is only doing the vertical-align but not the horizontal right?

                                        – V-SHY
                                        Mar 25 '15 at 3:38





                                        but this is only doing the vertical-align but not the horizontal right?

                                        – V-SHY
                                        Mar 25 '15 at 3:38




                                        1




                                        1





                                        It won't work if image's width larger than div's width.

                                        – Davuz
                                        May 26 '15 at 7:02





                                        It won't work if image's width larger than div's width.

                                        – Davuz
                                        May 26 '15 at 7:02




                                        4




                                        4





                                        If we remove display:table-cell; it works perfactly.

                                        – Ahesanali Momin
                                        May 18 '17 at 7:39





                                        If we remove display:table-cell; it works perfactly.

                                        – Ahesanali Momin
                                        May 18 '17 at 7:39











                                        87














                                        Seems to me that you also wanted that image to be vertically centered within the container. (I didn't see any answer that provided that)



                                        Working Fiddle:




                                        1. Pure CSS solution

                                        2. Not breaking the document flow (no floats or absolute positioning)

                                        3. Cross browser compatibility (even IE6)

                                        4. Completely responsive.


                                        HTML



                                        <div id="over">
                                        <span class="Centerer"></span>
                                        <img class="Centered" src="http://th07.deviantart.net/fs71/200H/f/2013/236/d/b/bw_avlonas_a5_beach_isles_wallpaper_image_by_lemnosexplorer-d6jh3i7.jpg" />
                                        </div>


                                        CSS



                                        *
                                        {
                                        padding: 0;
                                        margin: 0;
                                        }
                                        #over
                                        {
                                        position:absolute;
                                        width:100%;
                                        height:100%;
                                        text-align: center; /*handles the horizontal centering*/
                                        }
                                        /*handles the vertical centering*/
                                        .Centerer
                                        {
                                        display: inline-block;
                                        height: 100%;
                                        vertical-align: middle;
                                        }
                                        .Centered
                                        {
                                        display: inline-block;
                                        vertical-align: middle;
                                        }


                                        Note: this solution is good to align any element within any element.
                                        for IE7, when applying the .Centered class on block elements, you will have to use another trick to get the inline-block working. (that because IE6/IE7 dont play well with inline-block on block elements)






                                        share|improve this answer





















                                        • 10





                                          Only this one is working (vertical & horizontal)

                                          – Bartek Kosa
                                          Nov 13 '13 at 13:01






                                        • 1





                                          This is superb...Magic!!! Worked awesomly well! Thanks so much for this...

                                          – Nitin Bansal
                                          Jul 1 '14 at 10:55






                                        • 2





                                          excellent.. this should the answer to this question.

                                          – user3790264
                                          Sep 30 '14 at 10:59






                                        • 2





                                          Should be the accepted answer +1

                                          – Lehan Coetzee
                                          Feb 2 '16 at 11:17






                                        • 2





                                          Works perfectly!

                                          – wotaskd
                                          Jun 8 '16 at 14:28
















                                        87














                                        Seems to me that you also wanted that image to be vertically centered within the container. (I didn't see any answer that provided that)



                                        Working Fiddle:




                                        1. Pure CSS solution

                                        2. Not breaking the document flow (no floats or absolute positioning)

                                        3. Cross browser compatibility (even IE6)

                                        4. Completely responsive.


                                        HTML



                                        <div id="over">
                                        <span class="Centerer"></span>
                                        <img class="Centered" src="http://th07.deviantart.net/fs71/200H/f/2013/236/d/b/bw_avlonas_a5_beach_isles_wallpaper_image_by_lemnosexplorer-d6jh3i7.jpg" />
                                        </div>


                                        CSS



                                        *
                                        {
                                        padding: 0;
                                        margin: 0;
                                        }
                                        #over
                                        {
                                        position:absolute;
                                        width:100%;
                                        height:100%;
                                        text-align: center; /*handles the horizontal centering*/
                                        }
                                        /*handles the vertical centering*/
                                        .Centerer
                                        {
                                        display: inline-block;
                                        height: 100%;
                                        vertical-align: middle;
                                        }
                                        .Centered
                                        {
                                        display: inline-block;
                                        vertical-align: middle;
                                        }


                                        Note: this solution is good to align any element within any element.
                                        for IE7, when applying the .Centered class on block elements, you will have to use another trick to get the inline-block working. (that because IE6/IE7 dont play well with inline-block on block elements)






                                        share|improve this answer





















                                        • 10





                                          Only this one is working (vertical & horizontal)

                                          – Bartek Kosa
                                          Nov 13 '13 at 13:01






                                        • 1





                                          This is superb...Magic!!! Worked awesomly well! Thanks so much for this...

                                          – Nitin Bansal
                                          Jul 1 '14 at 10:55






                                        • 2





                                          excellent.. this should the answer to this question.

                                          – user3790264
                                          Sep 30 '14 at 10:59






                                        • 2





                                          Should be the accepted answer +1

                                          – Lehan Coetzee
                                          Feb 2 '16 at 11:17






                                        • 2





                                          Works perfectly!

                                          – wotaskd
                                          Jun 8 '16 at 14:28














                                        87












                                        87








                                        87







                                        Seems to me that you also wanted that image to be vertically centered within the container. (I didn't see any answer that provided that)



                                        Working Fiddle:




                                        1. Pure CSS solution

                                        2. Not breaking the document flow (no floats or absolute positioning)

                                        3. Cross browser compatibility (even IE6)

                                        4. Completely responsive.


                                        HTML



                                        <div id="over">
                                        <span class="Centerer"></span>
                                        <img class="Centered" src="http://th07.deviantart.net/fs71/200H/f/2013/236/d/b/bw_avlonas_a5_beach_isles_wallpaper_image_by_lemnosexplorer-d6jh3i7.jpg" />
                                        </div>


                                        CSS



                                        *
                                        {
                                        padding: 0;
                                        margin: 0;
                                        }
                                        #over
                                        {
                                        position:absolute;
                                        width:100%;
                                        height:100%;
                                        text-align: center; /*handles the horizontal centering*/
                                        }
                                        /*handles the vertical centering*/
                                        .Centerer
                                        {
                                        display: inline-block;
                                        height: 100%;
                                        vertical-align: middle;
                                        }
                                        .Centered
                                        {
                                        display: inline-block;
                                        vertical-align: middle;
                                        }


                                        Note: this solution is good to align any element within any element.
                                        for IE7, when applying the .Centered class on block elements, you will have to use another trick to get the inline-block working. (that because IE6/IE7 dont play well with inline-block on block elements)






                                        share|improve this answer















                                        Seems to me that you also wanted that image to be vertically centered within the container. (I didn't see any answer that provided that)



                                        Working Fiddle:




                                        1. Pure CSS solution

                                        2. Not breaking the document flow (no floats or absolute positioning)

                                        3. Cross browser compatibility (even IE6)

                                        4. Completely responsive.


                                        HTML



                                        <div id="over">
                                        <span class="Centerer"></span>
                                        <img class="Centered" src="http://th07.deviantart.net/fs71/200H/f/2013/236/d/b/bw_avlonas_a5_beach_isles_wallpaper_image_by_lemnosexplorer-d6jh3i7.jpg" />
                                        </div>


                                        CSS



                                        *
                                        {
                                        padding: 0;
                                        margin: 0;
                                        }
                                        #over
                                        {
                                        position:absolute;
                                        width:100%;
                                        height:100%;
                                        text-align: center; /*handles the horizontal centering*/
                                        }
                                        /*handles the vertical centering*/
                                        .Centerer
                                        {
                                        display: inline-block;
                                        height: 100%;
                                        vertical-align: middle;
                                        }
                                        .Centered
                                        {
                                        display: inline-block;
                                        vertical-align: middle;
                                        }


                                        Note: this solution is good to align any element within any element.
                                        for IE7, when applying the .Centered class on block elements, you will have to use another trick to get the inline-block working. (that because IE6/IE7 dont play well with inline-block on block elements)







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Feb 19 '14 at 9:46









                                        Tushar Gupta

                                        42.7k188391




                                        42.7k188391










                                        answered Sep 16 '13 at 14:24









                                        avrahamcoolavrahamcool

                                        11.2k23855




                                        11.2k23855








                                        • 10





                                          Only this one is working (vertical & horizontal)

                                          – Bartek Kosa
                                          Nov 13 '13 at 13:01






                                        • 1





                                          This is superb...Magic!!! Worked awesomly well! Thanks so much for this...

                                          – Nitin Bansal
                                          Jul 1 '14 at 10:55






                                        • 2





                                          excellent.. this should the answer to this question.

                                          – user3790264
                                          Sep 30 '14 at 10:59






                                        • 2





                                          Should be the accepted answer +1

                                          – Lehan Coetzee
                                          Feb 2 '16 at 11:17






                                        • 2





                                          Works perfectly!

                                          – wotaskd
                                          Jun 8 '16 at 14:28














                                        • 10





                                          Only this one is working (vertical & horizontal)

                                          – Bartek Kosa
                                          Nov 13 '13 at 13:01






                                        • 1





                                          This is superb...Magic!!! Worked awesomly well! Thanks so much for this...

                                          – Nitin Bansal
                                          Jul 1 '14 at 10:55






                                        • 2





                                          excellent.. this should the answer to this question.

                                          – user3790264
                                          Sep 30 '14 at 10:59






                                        • 2





                                          Should be the accepted answer +1

                                          – Lehan Coetzee
                                          Feb 2 '16 at 11:17






                                        • 2





                                          Works perfectly!

                                          – wotaskd
                                          Jun 8 '16 at 14:28








                                        10




                                        10





                                        Only this one is working (vertical & horizontal)

                                        – Bartek Kosa
                                        Nov 13 '13 at 13:01





                                        Only this one is working (vertical & horizontal)

                                        – Bartek Kosa
                                        Nov 13 '13 at 13:01




                                        1




                                        1





                                        This is superb...Magic!!! Worked awesomly well! Thanks so much for this...

                                        – Nitin Bansal
                                        Jul 1 '14 at 10:55





                                        This is superb...Magic!!! Worked awesomly well! Thanks so much for this...

                                        – Nitin Bansal
                                        Jul 1 '14 at 10:55




                                        2




                                        2





                                        excellent.. this should the answer to this question.

                                        – user3790264
                                        Sep 30 '14 at 10:59





                                        excellent.. this should the answer to this question.

                                        – user3790264
                                        Sep 30 '14 at 10:59




                                        2




                                        2





                                        Should be the accepted answer +1

                                        – Lehan Coetzee
                                        Feb 2 '16 at 11:17





                                        Should be the accepted answer +1

                                        – Lehan Coetzee
                                        Feb 2 '16 at 11:17




                                        2




                                        2





                                        Works perfectly!

                                        – wotaskd
                                        Jun 8 '16 at 14:28





                                        Works perfectly!

                                        – wotaskd
                                        Jun 8 '16 at 14:28











                                        86














                                        This can also be done using the Flexbox layout:



                                        STATIC SIZE




                                        .parent {
                                        display: flex;
                                        height: 300px; /* Or whatever */
                                        background-color: #000;
                                        }

                                        .child {
                                        width: 100px; /* Or whatever */
                                        height: 100px; /* Or whatever */
                                        margin: auto; /* Magic! */
                                        }

                                        <div class="parent">
                                        <img class="child" src="https://i.vimeocdn.com/portrait/58832_300x300"/>
                                        </div>





                                        DYNAMIC SIZE




                                        html, body {
                                        width: 100%;
                                        height: 100%;
                                        display: flex;
                                        background-color: #999;
                                        }

                                        * {
                                        margin: 0;
                                        padding: 0;
                                        }

                                        .parent {
                                        margin: auto;
                                        background-color: #000;
                                        display: flex;
                                        height: 80%;
                                        width: 80%;
                                        }

                                        .child {
                                        margin: auto; /* Magic! */
                                        max-width: 100%;
                                        max-height: 100%;
                                        }

                                        <div class="parent">
                                        <img class="child" src="https://i.vimeocdn.com/portrait/58832_300x300"/>
                                        </div>





                                        I found the example in this article, which does a great job explaining the how to use layout.






                                        share|improve this answer


























                                        • flex is state of the art - just works without tricks

                                          – Bernhard Zürn
                                          Jan 17 '17 at 20:02











                                        • In the Static Size, there's no need for width and height for the child (at least in my version of Firefox).

                                          – Rodrigo
                                          Jun 9 '17 at 13:23
















                                        86














                                        This can also be done using the Flexbox layout:



                                        STATIC SIZE




                                        .parent {
                                        display: flex;
                                        height: 300px; /* Or whatever */
                                        background-color: #000;
                                        }

                                        .child {
                                        width: 100px; /* Or whatever */
                                        height: 100px; /* Or whatever */
                                        margin: auto; /* Magic! */
                                        }

                                        <div class="parent">
                                        <img class="child" src="https://i.vimeocdn.com/portrait/58832_300x300"/>
                                        </div>





                                        DYNAMIC SIZE




                                        html, body {
                                        width: 100%;
                                        height: 100%;
                                        display: flex;
                                        background-color: #999;
                                        }

                                        * {
                                        margin: 0;
                                        padding: 0;
                                        }

                                        .parent {
                                        margin: auto;
                                        background-color: #000;
                                        display: flex;
                                        height: 80%;
                                        width: 80%;
                                        }

                                        .child {
                                        margin: auto; /* Magic! */
                                        max-width: 100%;
                                        max-height: 100%;
                                        }

                                        <div class="parent">
                                        <img class="child" src="https://i.vimeocdn.com/portrait/58832_300x300"/>
                                        </div>





                                        I found the example in this article, which does a great job explaining the how to use layout.






                                        share|improve this answer


























                                        • flex is state of the art - just works without tricks

                                          – Bernhard Zürn
                                          Jan 17 '17 at 20:02











                                        • In the Static Size, there's no need for width and height for the child (at least in my version of Firefox).

                                          – Rodrigo
                                          Jun 9 '17 at 13:23














                                        86












                                        86








                                        86







                                        This can also be done using the Flexbox layout:



                                        STATIC SIZE




                                        .parent {
                                        display: flex;
                                        height: 300px; /* Or whatever */
                                        background-color: #000;
                                        }

                                        .child {
                                        width: 100px; /* Or whatever */
                                        height: 100px; /* Or whatever */
                                        margin: auto; /* Magic! */
                                        }

                                        <div class="parent">
                                        <img class="child" src="https://i.vimeocdn.com/portrait/58832_300x300"/>
                                        </div>





                                        DYNAMIC SIZE




                                        html, body {
                                        width: 100%;
                                        height: 100%;
                                        display: flex;
                                        background-color: #999;
                                        }

                                        * {
                                        margin: 0;
                                        padding: 0;
                                        }

                                        .parent {
                                        margin: auto;
                                        background-color: #000;
                                        display: flex;
                                        height: 80%;
                                        width: 80%;
                                        }

                                        .child {
                                        margin: auto; /* Magic! */
                                        max-width: 100%;
                                        max-height: 100%;
                                        }

                                        <div class="parent">
                                        <img class="child" src="https://i.vimeocdn.com/portrait/58832_300x300"/>
                                        </div>





                                        I found the example in this article, which does a great job explaining the how to use layout.






                                        share|improve this answer















                                        This can also be done using the Flexbox layout:



                                        STATIC SIZE




                                        .parent {
                                        display: flex;
                                        height: 300px; /* Or whatever */
                                        background-color: #000;
                                        }

                                        .child {
                                        width: 100px; /* Or whatever */
                                        height: 100px; /* Or whatever */
                                        margin: auto; /* Magic! */
                                        }

                                        <div class="parent">
                                        <img class="child" src="https://i.vimeocdn.com/portrait/58832_300x300"/>
                                        </div>





                                        DYNAMIC SIZE




                                        html, body {
                                        width: 100%;
                                        height: 100%;
                                        display: flex;
                                        background-color: #999;
                                        }

                                        * {
                                        margin: 0;
                                        padding: 0;
                                        }

                                        .parent {
                                        margin: auto;
                                        background-color: #000;
                                        display: flex;
                                        height: 80%;
                                        width: 80%;
                                        }

                                        .child {
                                        margin: auto; /* Magic! */
                                        max-width: 100%;
                                        max-height: 100%;
                                        }

                                        <div class="parent">
                                        <img class="child" src="https://i.vimeocdn.com/portrait/58832_300x300"/>
                                        </div>





                                        I found the example in this article, which does a great job explaining the how to use layout.






                                        .parent {
                                        display: flex;
                                        height: 300px; /* Or whatever */
                                        background-color: #000;
                                        }

                                        .child {
                                        width: 100px; /* Or whatever */
                                        height: 100px; /* Or whatever */
                                        margin: auto; /* Magic! */
                                        }

                                        <div class="parent">
                                        <img class="child" src="https://i.vimeocdn.com/portrait/58832_300x300"/>
                                        </div>





                                        .parent {
                                        display: flex;
                                        height: 300px; /* Or whatever */
                                        background-color: #000;
                                        }

                                        .child {
                                        width: 100px; /* Or whatever */
                                        height: 100px; /* Or whatever */
                                        margin: auto; /* Magic! */
                                        }

                                        <div class="parent">
                                        <img class="child" src="https://i.vimeocdn.com/portrait/58832_300x300"/>
                                        </div>





                                        html, body {
                                        width: 100%;
                                        height: 100%;
                                        display: flex;
                                        background-color: #999;
                                        }

                                        * {
                                        margin: 0;
                                        padding: 0;
                                        }

                                        .parent {
                                        margin: auto;
                                        background-color: #000;
                                        display: flex;
                                        height: 80%;
                                        width: 80%;
                                        }

                                        .child {
                                        margin: auto; /* Magic! */
                                        max-width: 100%;
                                        max-height: 100%;
                                        }

                                        <div class="parent">
                                        <img class="child" src="https://i.vimeocdn.com/portrait/58832_300x300"/>
                                        </div>





                                        html, body {
                                        width: 100%;
                                        height: 100%;
                                        display: flex;
                                        background-color: #999;
                                        }

                                        * {
                                        margin: 0;
                                        padding: 0;
                                        }

                                        .parent {
                                        margin: auto;
                                        background-color: #000;
                                        display: flex;
                                        height: 80%;
                                        width: 80%;
                                        }

                                        .child {
                                        margin: auto; /* Magic! */
                                        max-width: 100%;
                                        max-height: 100%;
                                        }

                                        <div class="parent">
                                        <img class="child" src="https://i.vimeocdn.com/portrait/58832_300x300"/>
                                        </div>






                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Feb 27 '17 at 4:39









                                        Manatax

                                        1,89231937




                                        1,89231937










                                        answered May 6 '14 at 20:04









                                        aerdmanaerdman

                                        1,00473




                                        1,00473













                                        • flex is state of the art - just works without tricks

                                          – Bernhard Zürn
                                          Jan 17 '17 at 20:02











                                        • In the Static Size, there's no need for width and height for the child (at least in my version of Firefox).

                                          – Rodrigo
                                          Jun 9 '17 at 13:23



















                                        • flex is state of the art - just works without tricks

                                          – Bernhard Zürn
                                          Jan 17 '17 at 20:02











                                        • In the Static Size, there's no need for width and height for the child (at least in my version of Firefox).

                                          – Rodrigo
                                          Jun 9 '17 at 13:23

















                                        flex is state of the art - just works without tricks

                                        – Bernhard Zürn
                                        Jan 17 '17 at 20:02





                                        flex is state of the art - just works without tricks

                                        – Bernhard Zürn
                                        Jan 17 '17 at 20:02













                                        In the Static Size, there's no need for width and height for the child (at least in my version of Firefox).

                                        – Rodrigo
                                        Jun 9 '17 at 13:23





                                        In the Static Size, there's no need for width and height for the child (at least in my version of Firefox).

                                        – Rodrigo
                                        Jun 9 '17 at 13:23











                                        59














                                        img.centered {
                                        display: block;
                                        margin: auto auto;
                                        }





                                        share|improve this answer





















                                        • 1





                                          this is very similar to this answer

                                          – simple_human
                                          Jul 19 '14 at 0:29
















                                        59














                                        img.centered {
                                        display: block;
                                        margin: auto auto;
                                        }





                                        share|improve this answer





















                                        • 1





                                          this is very similar to this answer

                                          – simple_human
                                          Jul 19 '14 at 0:29














                                        59












                                        59








                                        59







                                        img.centered {
                                        display: block;
                                        margin: auto auto;
                                        }





                                        share|improve this answer















                                        img.centered {
                                        display: block;
                                        margin: auto auto;
                                        }






                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited May 26 '18 at 20:30









                                        Ronan Boiteau

                                        5,96451838




                                        5,96451838










                                        answered Jan 27 '14 at 7:38









                                        NitinNitin

                                        59144




                                        59144








                                        • 1





                                          this is very similar to this answer

                                          – simple_human
                                          Jul 19 '14 at 0:29














                                        • 1





                                          this is very similar to this answer

                                          – simple_human
                                          Jul 19 '14 at 0:29








                                        1




                                        1





                                        this is very similar to this answer

                                        – simple_human
                                        Jul 19 '14 at 0:29





                                        this is very similar to this answer

                                        – simple_human
                                        Jul 19 '14 at 0:29











                                        27














                                        #over {position:relative; text-align:center; 
                                        width:100%; height:100%; background:#CCC;}

                                        #over img{
                                        position: absolute;
                                        margin: auto;
                                        top: 0;
                                        left: 0;
                                        right: 0;
                                        bottom: 0;
                                        }





                                        share|improve this answer


























                                        • Best solution that actually works.

                                          – Burjua
                                          Jun 15 '17 at 13:10











                                        • This is the right answer, that actually centers both vertically and horizontally.

                                          – Alexander Kim
                                          Jun 7 '18 at 8:44











                                        • Best answer so far.

                                          – kiran puppala
                                          Jan 31 at 9:02
















                                        27














                                        #over {position:relative; text-align:center; 
                                        width:100%; height:100%; background:#CCC;}

                                        #over img{
                                        position: absolute;
                                        margin: auto;
                                        top: 0;
                                        left: 0;
                                        right: 0;
                                        bottom: 0;
                                        }





                                        share|improve this answer


























                                        • Best solution that actually works.

                                          – Burjua
                                          Jun 15 '17 at 13:10











                                        • This is the right answer, that actually centers both vertically and horizontally.

                                          – Alexander Kim
                                          Jun 7 '18 at 8:44











                                        • Best answer so far.

                                          – kiran puppala
                                          Jan 31 at 9:02














                                        27












                                        27








                                        27







                                        #over {position:relative; text-align:center; 
                                        width:100%; height:100%; background:#CCC;}

                                        #over img{
                                        position: absolute;
                                        margin: auto;
                                        top: 0;
                                        left: 0;
                                        right: 0;
                                        bottom: 0;
                                        }





                                        share|improve this answer















                                        #over {position:relative; text-align:center; 
                                        width:100%; height:100%; background:#CCC;}

                                        #over img{
                                        position: absolute;
                                        margin: auto;
                                        top: 0;
                                        left: 0;
                                        right: 0;
                                        bottom: 0;
                                        }






                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Feb 19 '14 at 9:46









                                        Tushar Gupta

                                        42.7k188391




                                        42.7k188391










                                        answered May 11 '13 at 17:27









                                        dhirdhir

                                        27133




                                        27133













                                        • Best solution that actually works.

                                          – Burjua
                                          Jun 15 '17 at 13:10











                                        • This is the right answer, that actually centers both vertically and horizontally.

                                          – Alexander Kim
                                          Jun 7 '18 at 8:44











                                        • Best answer so far.

                                          – kiran puppala
                                          Jan 31 at 9:02



















                                        • Best solution that actually works.

                                          – Burjua
                                          Jun 15 '17 at 13:10











                                        • This is the right answer, that actually centers both vertically and horizontally.

                                          – Alexander Kim
                                          Jun 7 '18 at 8:44











                                        • Best answer so far.

                                          – kiran puppala
                                          Jan 31 at 9:02

















                                        Best solution that actually works.

                                        – Burjua
                                        Jun 15 '17 at 13:10





                                        Best solution that actually works.

                                        – Burjua
                                        Jun 15 '17 at 13:10













                                        This is the right answer, that actually centers both vertically and horizontally.

                                        – Alexander Kim
                                        Jun 7 '18 at 8:44





                                        This is the right answer, that actually centers both vertically and horizontally.

                                        – Alexander Kim
                                        Jun 7 '18 at 8:44













                                        Best answer so far.

                                        – kiran puppala
                                        Jan 31 at 9:02





                                        Best answer so far.

                                        – kiran puppala
                                        Jan 31 at 9:02











                                        25














                                        You can do this easily by using display:flex css property



                                        #over {
                                        height: 100%;
                                        width: 100%;
                                        display: flex;
                                        align-items: center;
                                        justify-content: center;
                                        }





                                        share|improve this answer






























                                          25














                                          You can do this easily by using display:flex css property



                                          #over {
                                          height: 100%;
                                          width: 100%;
                                          display: flex;
                                          align-items: center;
                                          justify-content: center;
                                          }





                                          share|improve this answer




























                                            25












                                            25








                                            25







                                            You can do this easily by using display:flex css property



                                            #over {
                                            height: 100%;
                                            width: 100%;
                                            display: flex;
                                            align-items: center;
                                            justify-content: center;
                                            }





                                            share|improve this answer















                                            You can do this easily by using display:flex css property



                                            #over {
                                            height: 100%;
                                            width: 100%;
                                            display: flex;
                                            align-items: center;
                                            justify-content: center;
                                            }






                                            share|improve this answer














                                            share|improve this answer



                                            share|improve this answer








                                            edited Jan 11 at 8:37









                                            crmpicco

                                            8,5581788158




                                            8,5581788158










                                            answered Nov 14 '17 at 15:41









                                            tanveer ahmad dartanveer ahmad dar

                                            2,2541725




                                            2,2541725























                                                11














                                                I still had some issues with other solution presented here. Finally this worked best for me:



                                                <div class="parent">
                                                <img class="child" src="image.png"/>
                                                </div>


                                                css3:



                                                .child {
                                                display: block;
                                                position: absolute;
                                                top: 50%;
                                                left: 50%;
                                                transform: translate(-50%, -50%);
                                                -webkit-transform: translate(-50%, -50%); /* Safari and Chrome */
                                                -moz-transform: translate(-50%, -50%); /* Firefox */
                                                -ms-transform: translate(-50%, -50%); /* IE 9 */
                                                -o-transform: translate(-50%, -50%); /* Opera */
                                                // I suppose you may like those too:
                                                // max-width: 80%;
                                                // max-height: 80%;
                                                }


                                                You can read more about that approach at this page.






                                                share|improve this answer
























                                                • I had to also add parent css but your code worked perfectly! position: relative; width: 100%; float: left; overflow: hidden; min-height: 189px;

                                                  – user2593040
                                                  Dec 9 '16 at 9:12
















                                                11














                                                I still had some issues with other solution presented here. Finally this worked best for me:



                                                <div class="parent">
                                                <img class="child" src="image.png"/>
                                                </div>


                                                css3:



                                                .child {
                                                display: block;
                                                position: absolute;
                                                top: 50%;
                                                left: 50%;
                                                transform: translate(-50%, -50%);
                                                -webkit-transform: translate(-50%, -50%); /* Safari and Chrome */
                                                -moz-transform: translate(-50%, -50%); /* Firefox */
                                                -ms-transform: translate(-50%, -50%); /* IE 9 */
                                                -o-transform: translate(-50%, -50%); /* Opera */
                                                // I suppose you may like those too:
                                                // max-width: 80%;
                                                // max-height: 80%;
                                                }


                                                You can read more about that approach at this page.






                                                share|improve this answer
























                                                • I had to also add parent css but your code worked perfectly! position: relative; width: 100%; float: left; overflow: hidden; min-height: 189px;

                                                  – user2593040
                                                  Dec 9 '16 at 9:12














                                                11












                                                11








                                                11







                                                I still had some issues with other solution presented here. Finally this worked best for me:



                                                <div class="parent">
                                                <img class="child" src="image.png"/>
                                                </div>


                                                css3:



                                                .child {
                                                display: block;
                                                position: absolute;
                                                top: 50%;
                                                left: 50%;
                                                transform: translate(-50%, -50%);
                                                -webkit-transform: translate(-50%, -50%); /* Safari and Chrome */
                                                -moz-transform: translate(-50%, -50%); /* Firefox */
                                                -ms-transform: translate(-50%, -50%); /* IE 9 */
                                                -o-transform: translate(-50%, -50%); /* Opera */
                                                // I suppose you may like those too:
                                                // max-width: 80%;
                                                // max-height: 80%;
                                                }


                                                You can read more about that approach at this page.






                                                share|improve this answer













                                                I still had some issues with other solution presented here. Finally this worked best for me:



                                                <div class="parent">
                                                <img class="child" src="image.png"/>
                                                </div>


                                                css3:



                                                .child {
                                                display: block;
                                                position: absolute;
                                                top: 50%;
                                                left: 50%;
                                                transform: translate(-50%, -50%);
                                                -webkit-transform: translate(-50%, -50%); /* Safari and Chrome */
                                                -moz-transform: translate(-50%, -50%); /* Firefox */
                                                -ms-transform: translate(-50%, -50%); /* IE 9 */
                                                -o-transform: translate(-50%, -50%); /* Opera */
                                                // I suppose you may like those too:
                                                // max-width: 80%;
                                                // max-height: 80%;
                                                }


                                                You can read more about that approach at this page.







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Jan 14 '15 at 18:42









                                                pawel7318pawel7318

                                                1,9971734




                                                1,9971734













                                                • I had to also add parent css but your code worked perfectly! position: relative; width: 100%; float: left; overflow: hidden; min-height: 189px;

                                                  – user2593040
                                                  Dec 9 '16 at 9:12



















                                                • I had to also add parent css but your code worked perfectly! position: relative; width: 100%; float: left; overflow: hidden; min-height: 189px;

                                                  – user2593040
                                                  Dec 9 '16 at 9:12

















                                                I had to also add parent css but your code worked perfectly! position: relative; width: 100%; float: left; overflow: hidden; min-height: 189px;

                                                – user2593040
                                                Dec 9 '16 at 9:12





                                                I had to also add parent css but your code worked perfectly! position: relative; width: 100%; float: left; overflow: hidden; min-height: 189px;

                                                – user2593040
                                                Dec 9 '16 at 9:12











                                                10














                                                Basically, setting right and left margin to auto will cause the image to center align.



                                                <div id="over" style="position:absolute; width:100%; height:100%>
                                                <img src="img.png" style="display: block; margin: 0 auto;">
                                                </div>





                                                share|improve this answer






























                                                  10














                                                  Basically, setting right and left margin to auto will cause the image to center align.



                                                  <div id="over" style="position:absolute; width:100%; height:100%>
                                                  <img src="img.png" style="display: block; margin: 0 auto;">
                                                  </div>





                                                  share|improve this answer




























                                                    10












                                                    10








                                                    10







                                                    Basically, setting right and left margin to auto will cause the image to center align.



                                                    <div id="over" style="position:absolute; width:100%; height:100%>
                                                    <img src="img.png" style="display: block; margin: 0 auto;">
                                                    </div>





                                                    share|improve this answer















                                                    Basically, setting right and left margin to auto will cause the image to center align.



                                                    <div id="over" style="position:absolute; width:100%; height:100%>
                                                    <img src="img.png" style="display: block; margin: 0 auto;">
                                                    </div>






                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Feb 7 '13 at 22:57









                                                    Reine Johansson

                                                    14814




                                                    14814










                                                    answered Dec 8 '12 at 5:29









                                                    GarconisGarconis

                                                    575518




                                                    575518























                                                        8














                                                        This would be a simpler approach



                                                        #over > img{
                                                        display: block;
                                                        margin:0 auto;
                                                        }





                                                        share|improve this answer






























                                                          8














                                                          This would be a simpler approach



                                                          #over > img{
                                                          display: block;
                                                          margin:0 auto;
                                                          }





                                                          share|improve this answer




























                                                            8












                                                            8








                                                            8







                                                            This would be a simpler approach



                                                            #over > img{
                                                            display: block;
                                                            margin:0 auto;
                                                            }





                                                            share|improve this answer















                                                            This would be a simpler approach



                                                            #over > img{
                                                            display: block;
                                                            margin:0 auto;
                                                            }






                                                            share|improve this answer














                                                            share|improve this answer



                                                            share|improve this answer








                                                            edited Jun 10 '15 at 5:53









                                                            Subedi Kishor

                                                            4,68752849




                                                            4,68752849










                                                            answered Jun 10 '15 at 5:21









                                                            Sujay sreedharSujay sreedhar

                                                            3,26321625




                                                            3,26321625























                                                                6














                                                                setting the img to display:inline-block while having set the superior div to text-align:center will do the job too



                                                                EDIT: to those folks who are playing with display:inline-block >>> don't forget that e.g. two divs like



                                                                <div>Div1 content</div>NOSPACEHERE<div>Div2 content</div>


                                                                really have no spaces between them (as seen here).



                                                                Just basic to avoid these (inline block inherent) gaps between them. These gaps can be seen between every two words I'm writing right now! :-) So .. hope this helps some of you.






                                                                share|improve this answer






























                                                                  6














                                                                  setting the img to display:inline-block while having set the superior div to text-align:center will do the job too



                                                                  EDIT: to those folks who are playing with display:inline-block >>> don't forget that e.g. two divs like



                                                                  <div>Div1 content</div>NOSPACEHERE<div>Div2 content</div>


                                                                  really have no spaces between them (as seen here).



                                                                  Just basic to avoid these (inline block inherent) gaps between them. These gaps can be seen between every two words I'm writing right now! :-) So .. hope this helps some of you.






                                                                  share|improve this answer




























                                                                    6












                                                                    6








                                                                    6







                                                                    setting the img to display:inline-block while having set the superior div to text-align:center will do the job too



                                                                    EDIT: to those folks who are playing with display:inline-block >>> don't forget that e.g. two divs like



                                                                    <div>Div1 content</div>NOSPACEHERE<div>Div2 content</div>


                                                                    really have no spaces between them (as seen here).



                                                                    Just basic to avoid these (inline block inherent) gaps between them. These gaps can be seen between every two words I'm writing right now! :-) So .. hope this helps some of you.






                                                                    share|improve this answer















                                                                    setting the img to display:inline-block while having set the superior div to text-align:center will do the job too



                                                                    EDIT: to those folks who are playing with display:inline-block >>> don't forget that e.g. two divs like



                                                                    <div>Div1 content</div>NOSPACEHERE<div>Div2 content</div>


                                                                    really have no spaces between them (as seen here).



                                                                    Just basic to avoid these (inline block inherent) gaps between them. These gaps can be seen between every two words I'm writing right now! :-) So .. hope this helps some of you.







                                                                    share|improve this answer














                                                                    share|improve this answer



                                                                    share|improve this answer








                                                                    edited Oct 25 '15 at 2:44

























                                                                    answered Apr 12 '13 at 17:16









                                                                    sashasasha

                                                                    496617




                                                                    496617























                                                                        6














                                                                        SIMPLE. 2018. FlexBox. To Check Browser Support - Can I Use


                                                                        Minimal Solution:



                                                                        div#over { 
                                                                        display: flex;
                                                                        justify-content: center;
                                                                        align-items: center;
                                                                        }





                                                                        To get the widest browser support possible:



                                                                        div#over { 
                                                                        display: -webkit-flex;
                                                                        display: -ms-flex;
                                                                        display: flex;
                                                                        justify-content: center;
                                                                        -ms-align-items: center;
                                                                        align-items: center;
                                                                        }





                                                                        share|improve this answer






























                                                                          6














                                                                          SIMPLE. 2018. FlexBox. To Check Browser Support - Can I Use


                                                                          Minimal Solution:



                                                                          div#over { 
                                                                          display: flex;
                                                                          justify-content: center;
                                                                          align-items: center;
                                                                          }





                                                                          To get the widest browser support possible:



                                                                          div#over { 
                                                                          display: -webkit-flex;
                                                                          display: -ms-flex;
                                                                          display: flex;
                                                                          justify-content: center;
                                                                          -ms-align-items: center;
                                                                          align-items: center;
                                                                          }





                                                                          share|improve this answer




























                                                                            6












                                                                            6








                                                                            6







                                                                            SIMPLE. 2018. FlexBox. To Check Browser Support - Can I Use


                                                                            Minimal Solution:



                                                                            div#over { 
                                                                            display: flex;
                                                                            justify-content: center;
                                                                            align-items: center;
                                                                            }





                                                                            To get the widest browser support possible:



                                                                            div#over { 
                                                                            display: -webkit-flex;
                                                                            display: -ms-flex;
                                                                            display: flex;
                                                                            justify-content: center;
                                                                            -ms-align-items: center;
                                                                            align-items: center;
                                                                            }





                                                                            share|improve this answer















                                                                            SIMPLE. 2018. FlexBox. To Check Browser Support - Can I Use


                                                                            Minimal Solution:



                                                                            div#over { 
                                                                            display: flex;
                                                                            justify-content: center;
                                                                            align-items: center;
                                                                            }





                                                                            To get the widest browser support possible:



                                                                            div#over { 
                                                                            display: -webkit-flex;
                                                                            display: -ms-flex;
                                                                            display: flex;
                                                                            justify-content: center;
                                                                            -ms-align-items: center;
                                                                            align-items: center;
                                                                            }






                                                                            share|improve this answer














                                                                            share|improve this answer



                                                                            share|improve this answer








                                                                            edited Jun 26 '18 at 13:01









                                                                            Calvin Nunes

                                                                            3,71831135




                                                                            3,71831135










                                                                            answered May 30 '18 at 10:05









                                                                            NadavNadav

                                                                            338310




                                                                            338310























                                                                                5














                                                                                I've tried many approaches but only this one works for multiple inline elements inside a container div. Here is code to align everything in div at middle.



                                                                                CSS



                                                                                .divContainer
                                                                                {
                                                                                vertical-align: middle;
                                                                                text-align: center; <!-- If you want horizontal center alignment -->
                                                                                }
                                                                                .divContainer > *
                                                                                {
                                                                                vertical-align: middle;
                                                                                }


                                                                                HTML



                                                                                <div class="divContainer">
                                                                                <span>Middle Text</span>
                                                                                <img src="test.png"/>
                                                                                </div>


                                                                                Sample code is here: https://jsfiddle.net/yogendrasinh/2vq0c68m/






                                                                                share|improve this answer




























                                                                                  5














                                                                                  I've tried many approaches but only this one works for multiple inline elements inside a container div. Here is code to align everything in div at middle.



                                                                                  CSS



                                                                                  .divContainer
                                                                                  {
                                                                                  vertical-align: middle;
                                                                                  text-align: center; <!-- If you want horizontal center alignment -->
                                                                                  }
                                                                                  .divContainer > *
                                                                                  {
                                                                                  vertical-align: middle;
                                                                                  }


                                                                                  HTML



                                                                                  <div class="divContainer">
                                                                                  <span>Middle Text</span>
                                                                                  <img src="test.png"/>
                                                                                  </div>


                                                                                  Sample code is here: https://jsfiddle.net/yogendrasinh/2vq0c68m/






                                                                                  share|improve this answer


























                                                                                    5












                                                                                    5








                                                                                    5







                                                                                    I've tried many approaches but only this one works for multiple inline elements inside a container div. Here is code to align everything in div at middle.



                                                                                    CSS



                                                                                    .divContainer
                                                                                    {
                                                                                    vertical-align: middle;
                                                                                    text-align: center; <!-- If you want horizontal center alignment -->
                                                                                    }
                                                                                    .divContainer > *
                                                                                    {
                                                                                    vertical-align: middle;
                                                                                    }


                                                                                    HTML



                                                                                    <div class="divContainer">
                                                                                    <span>Middle Text</span>
                                                                                    <img src="test.png"/>
                                                                                    </div>


                                                                                    Sample code is here: https://jsfiddle.net/yogendrasinh/2vq0c68m/






                                                                                    share|improve this answer













                                                                                    I've tried many approaches but only this one works for multiple inline elements inside a container div. Here is code to align everything in div at middle.



                                                                                    CSS



                                                                                    .divContainer
                                                                                    {
                                                                                    vertical-align: middle;
                                                                                    text-align: center; <!-- If you want horizontal center alignment -->
                                                                                    }
                                                                                    .divContainer > *
                                                                                    {
                                                                                    vertical-align: middle;
                                                                                    }


                                                                                    HTML



                                                                                    <div class="divContainer">
                                                                                    <span>Middle Text</span>
                                                                                    <img src="test.png"/>
                                                                                    </div>


                                                                                    Sample code is here: https://jsfiddle.net/yogendrasinh/2vq0c68m/







                                                                                    share|improve this answer












                                                                                    share|improve this answer



                                                                                    share|improve this answer










                                                                                    answered Aug 16 '16 at 22:52









                                                                                    YogeeYogee

                                                                                    1,0961018




                                                                                    1,0961018























                                                                                        5














                                                                                        CSS File



                                                                                        .over {
                                                                                        display : block;
                                                                                        margin : 0px auto;





                                                                                        share|improve this answer






























                                                                                          5














                                                                                          CSS File



                                                                                          .over {
                                                                                          display : block;
                                                                                          margin : 0px auto;





                                                                                          share|improve this answer




























                                                                                            5












                                                                                            5








                                                                                            5







                                                                                            CSS File



                                                                                            .over {
                                                                                            display : block;
                                                                                            margin : 0px auto;





                                                                                            share|improve this answer















                                                                                            CSS File



                                                                                            .over {
                                                                                            display : block;
                                                                                            margin : 0px auto;






                                                                                            share|improve this answer














                                                                                            share|improve this answer



                                                                                            share|improve this answer








                                                                                            edited Oct 3 '17 at 12:57









                                                                                            lapinkoira

                                                                                            3,49532245




                                                                                            3,49532245










                                                                                            answered Oct 3 '17 at 11:49









                                                                                            Sabarish RSabarish R

                                                                                            6112




                                                                                            6112























                                                                                                3














                                                                                                Try this minimal code:



                                                                                                <div class="outer">
                                                                                                <img src="image.png"/>
                                                                                                </div>


                                                                                                And CSS:



                                                                                                .outer{
                                                                                                text-align: center;
                                                                                                }
                                                                                                .outer img{
                                                                                                display: inline-block;
                                                                                                }





                                                                                                share|improve this answer






























                                                                                                  3














                                                                                                  Try this minimal code:



                                                                                                  <div class="outer">
                                                                                                  <img src="image.png"/>
                                                                                                  </div>


                                                                                                  And CSS:



                                                                                                  .outer{
                                                                                                  text-align: center;
                                                                                                  }
                                                                                                  .outer img{
                                                                                                  display: inline-block;
                                                                                                  }





                                                                                                  share|improve this answer




























                                                                                                    3












                                                                                                    3








                                                                                                    3







                                                                                                    Try this minimal code:



                                                                                                    <div class="outer">
                                                                                                    <img src="image.png"/>
                                                                                                    </div>


                                                                                                    And CSS:



                                                                                                    .outer{
                                                                                                    text-align: center;
                                                                                                    }
                                                                                                    .outer img{
                                                                                                    display: inline-block;
                                                                                                    }





                                                                                                    share|improve this answer















                                                                                                    Try this minimal code:



                                                                                                    <div class="outer">
                                                                                                    <img src="image.png"/>
                                                                                                    </div>


                                                                                                    And CSS:



                                                                                                    .outer{
                                                                                                    text-align: center;
                                                                                                    }
                                                                                                    .outer img{
                                                                                                    display: inline-block;
                                                                                                    }






                                                                                                    share|improve this answer














                                                                                                    share|improve this answer



                                                                                                    share|improve this answer








                                                                                                    edited Feb 19 '14 at 9:45









                                                                                                    Tushar Gupta

                                                                                                    42.7k188391




                                                                                                    42.7k188391










                                                                                                    answered Feb 7 '14 at 0:08









                                                                                                    luchopintadoluchopintado

                                                                                                    697711




                                                                                                    697711























                                                                                                        2














                                                                                                        many answer suggests to use margin:0 auto but this works only when the element you trying to make centered is not floating on left or right, that is float css attribute isn't set. In order to do this apply display attribute to table-cell and then apply margin of left and right to auto so your style will look like style="display:table-cell;margin:0 auto;"






                                                                                                        share|improve this answer




























                                                                                                          2














                                                                                                          many answer suggests to use margin:0 auto but this works only when the element you trying to make centered is not floating on left or right, that is float css attribute isn't set. In order to do this apply display attribute to table-cell and then apply margin of left and right to auto so your style will look like style="display:table-cell;margin:0 auto;"






                                                                                                          share|improve this answer


























                                                                                                            2












                                                                                                            2








                                                                                                            2







                                                                                                            many answer suggests to use margin:0 auto but this works only when the element you trying to make centered is not floating on left or right, that is float css attribute isn't set. In order to do this apply display attribute to table-cell and then apply margin of left and right to auto so your style will look like style="display:table-cell;margin:0 auto;"






                                                                                                            share|improve this answer













                                                                                                            many answer suggests to use margin:0 auto but this works only when the element you trying to make centered is not floating on left or right, that is float css attribute isn't set. In order to do this apply display attribute to table-cell and then apply margin of left and right to auto so your style will look like style="display:table-cell;margin:0 auto;"







                                                                                                            share|improve this answer












                                                                                                            share|improve this answer



                                                                                                            share|improve this answer










                                                                                                            answered Apr 21 '13 at 12:34









                                                                                                            vikas devdevikas devde

                                                                                                            8,08882939




                                                                                                            8,08882939























                                                                                                                2














                                                                                                                    <div>
                                                                                                                <p style="text-align:center; margin-top:0px; margin-bottom:0px; padding:0px;">
                                                                                                                <img src="image.jpg" alt="image"/>
                                                                                                                </p>
                                                                                                                </div>





                                                                                                                share|improve this answer




























                                                                                                                  2














                                                                                                                      <div>
                                                                                                                  <p style="text-align:center; margin-top:0px; margin-bottom:0px; padding:0px;">
                                                                                                                  <img src="image.jpg" alt="image"/>
                                                                                                                  </p>
                                                                                                                  </div>





                                                                                                                  share|improve this answer


























                                                                                                                    2












                                                                                                                    2








                                                                                                                    2







                                                                                                                        <div>
                                                                                                                    <p style="text-align:center; margin-top:0px; margin-bottom:0px; padding:0px;">
                                                                                                                    <img src="image.jpg" alt="image"/>
                                                                                                                    </p>
                                                                                                                    </div>





                                                                                                                    share|improve this answer













                                                                                                                        <div>
                                                                                                                    <p style="text-align:center; margin-top:0px; margin-bottom:0px; padding:0px;">
                                                                                                                    <img src="image.jpg" alt="image"/>
                                                                                                                    </p>
                                                                                                                    </div>






                                                                                                                    share|improve this answer












                                                                                                                    share|improve this answer



                                                                                                                    share|improve this answer










                                                                                                                    answered Sep 5 '13 at 8:49









                                                                                                                    betty.88betty.88

                                                                                                                    995




                                                                                                                    995























                                                                                                                        2














                                                                                                                        HTML:



                                                                                                                        <div id="over">
                                                                                                                        <img src="img.png">
                                                                                                                        </div>


                                                                                                                        CSS:



                                                                                                                        #over {
                                                                                                                        text-align: center;
                                                                                                                        }

                                                                                                                        #over img {
                                                                                                                        vertical-align: middle;
                                                                                                                        }





                                                                                                                        share|improve this answer


























                                                                                                                        • It's best if you add some commentary and not just toss code out there.

                                                                                                                          – Parkash Kumar
                                                                                                                          Oct 26 '15 at 10:43
















                                                                                                                        2














                                                                                                                        HTML:



                                                                                                                        <div id="over">
                                                                                                                        <img src="img.png">
                                                                                                                        </div>


                                                                                                                        CSS:



                                                                                                                        #over {
                                                                                                                        text-align: center;
                                                                                                                        }

                                                                                                                        #over img {
                                                                                                                        vertical-align: middle;
                                                                                                                        }





                                                                                                                        share|improve this answer


























                                                                                                                        • It's best if you add some commentary and not just toss code out there.

                                                                                                                          – Parkash Kumar
                                                                                                                          Oct 26 '15 at 10:43














                                                                                                                        2












                                                                                                                        2








                                                                                                                        2







                                                                                                                        HTML:



                                                                                                                        <div id="over">
                                                                                                                        <img src="img.png">
                                                                                                                        </div>


                                                                                                                        CSS:



                                                                                                                        #over {
                                                                                                                        text-align: center;
                                                                                                                        }

                                                                                                                        #over img {
                                                                                                                        vertical-align: middle;
                                                                                                                        }





                                                                                                                        share|improve this answer















                                                                                                                        HTML:



                                                                                                                        <div id="over">
                                                                                                                        <img src="img.png">
                                                                                                                        </div>


                                                                                                                        CSS:



                                                                                                                        #over {
                                                                                                                        text-align: center;
                                                                                                                        }

                                                                                                                        #over img {
                                                                                                                        vertical-align: middle;
                                                                                                                        }






                                                                                                                        share|improve this answer














                                                                                                                        share|improve this answer



                                                                                                                        share|improve this answer








                                                                                                                        edited Oct 26 '15 at 10:44









                                                                                                                        Parkash Kumar

                                                                                                                        4,26131937




                                                                                                                        4,26131937










                                                                                                                        answered Oct 25 '15 at 4:08









                                                                                                                        LahoriLahori

                                                                                                                        409212




                                                                                                                        409212













                                                                                                                        • It's best if you add some commentary and not just toss code out there.

                                                                                                                          – Parkash Kumar
                                                                                                                          Oct 26 '15 at 10:43



















                                                                                                                        • It's best if you add some commentary and not just toss code out there.

                                                                                                                          – Parkash Kumar
                                                                                                                          Oct 26 '15 at 10:43

















                                                                                                                        It's best if you add some commentary and not just toss code out there.

                                                                                                                        – Parkash Kumar
                                                                                                                        Oct 26 '15 at 10:43





                                                                                                                        It's best if you add some commentary and not just toss code out there.

                                                                                                                        – Parkash Kumar
                                                                                                                        Oct 26 '15 at 10:43











                                                                                                                        2














                                                                                                                        For center horizontally Just put



                                                                                                                        #over img {
                                                                                                                        display: block;
                                                                                                                        margin: 0 auto;
                                                                                                                        clear:both;
                                                                                                                        }


                                                                                                                        Another method:



                                                                                                                        #over img {
                                                                                                                        display: inline-block;
                                                                                                                        text-align: center;
                                                                                                                        }


                                                                                                                        For center vertically Just put:



                                                                                                                           #over img {

                                                                                                                        vertical-align: middle;
                                                                                                                        }





                                                                                                                        share|improve this answer






























                                                                                                                          2














                                                                                                                          For center horizontally Just put



                                                                                                                          #over img {
                                                                                                                          display: block;
                                                                                                                          margin: 0 auto;
                                                                                                                          clear:both;
                                                                                                                          }


                                                                                                                          Another method:



                                                                                                                          #over img {
                                                                                                                          display: inline-block;
                                                                                                                          text-align: center;
                                                                                                                          }


                                                                                                                          For center vertically Just put:



                                                                                                                             #over img {

                                                                                                                          vertical-align: middle;
                                                                                                                          }





                                                                                                                          share|improve this answer




























                                                                                                                            2












                                                                                                                            2








                                                                                                                            2







                                                                                                                            For center horizontally Just put



                                                                                                                            #over img {
                                                                                                                            display: block;
                                                                                                                            margin: 0 auto;
                                                                                                                            clear:both;
                                                                                                                            }


                                                                                                                            Another method:



                                                                                                                            #over img {
                                                                                                                            display: inline-block;
                                                                                                                            text-align: center;
                                                                                                                            }


                                                                                                                            For center vertically Just put:



                                                                                                                               #over img {

                                                                                                                            vertical-align: middle;
                                                                                                                            }





                                                                                                                            share|improve this answer















                                                                                                                            For center horizontally Just put



                                                                                                                            #over img {
                                                                                                                            display: block;
                                                                                                                            margin: 0 auto;
                                                                                                                            clear:both;
                                                                                                                            }


                                                                                                                            Another method:



                                                                                                                            #over img {
                                                                                                                            display: inline-block;
                                                                                                                            text-align: center;
                                                                                                                            }


                                                                                                                            For center vertically Just put:



                                                                                                                               #over img {

                                                                                                                            vertical-align: middle;
                                                                                                                            }






                                                                                                                            share|improve this answer














                                                                                                                            share|improve this answer



                                                                                                                            share|improve this answer








                                                                                                                            edited Jul 14 '16 at 6:28

























                                                                                                                            answered Feb 16 '16 at 10:37









                                                                                                                            Sanjib DebnathSanjib Debnath

                                                                                                                            1,1241212




                                                                                                                            1,1241212























                                                                                                                                2














                                                                                                                                This worked for me:



                                                                                                                                #image-id {
                                                                                                                                position: absolute;
                                                                                                                                top: 0; left: 0; right: 0; bottom: 0;
                                                                                                                                width: auto;
                                                                                                                                margin: 0 auto;
                                                                                                                                }





                                                                                                                                share|improve this answer




























                                                                                                                                  2














                                                                                                                                  This worked for me:



                                                                                                                                  #image-id {
                                                                                                                                  position: absolute;
                                                                                                                                  top: 0; left: 0; right: 0; bottom: 0;
                                                                                                                                  width: auto;
                                                                                                                                  margin: 0 auto;
                                                                                                                                  }





                                                                                                                                  share|improve this answer


























                                                                                                                                    2












                                                                                                                                    2








                                                                                                                                    2







                                                                                                                                    This worked for me:



                                                                                                                                    #image-id {
                                                                                                                                    position: absolute;
                                                                                                                                    top: 0; left: 0; right: 0; bottom: 0;
                                                                                                                                    width: auto;
                                                                                                                                    margin: 0 auto;
                                                                                                                                    }





                                                                                                                                    share|improve this answer













                                                                                                                                    This worked for me:



                                                                                                                                    #image-id {
                                                                                                                                    position: absolute;
                                                                                                                                    top: 0; left: 0; right: 0; bottom: 0;
                                                                                                                                    width: auto;
                                                                                                                                    margin: 0 auto;
                                                                                                                                    }






                                                                                                                                    share|improve this answer












                                                                                                                                    share|improve this answer



                                                                                                                                    share|improve this answer










                                                                                                                                    answered Jul 28 '16 at 1:53









                                                                                                                                    SileriaSileria

                                                                                                                                    11.8k43624




                                                                                                                                    11.8k43624























                                                                                                                                        2














                                                                                                                                        Well, we are in 2016... why not use flexbox?
                                                                                                                                        It's also responsive. Enjoy.




                                                                                                                                        #over{
                                                                                                                                        display:flex;
                                                                                                                                        align-items:center;
                                                                                                                                        justify-content:center;
                                                                                                                                        }

                                                                                                                                        <div id="over">
                                                                                                                                        <img src="http://www.garcard.com/images/garcard_symbol.png">
                                                                                                                                        </div>








                                                                                                                                        share|improve this answer



















                                                                                                                                        • 1





                                                                                                                                          Love css3! Thank you. However, its good to note that this will only work in modern browsers (except IE). All other browsers will have no effect.

                                                                                                                                          – Neel
                                                                                                                                          Jan 9 '17 at 16:44


















                                                                                                                                        2














                                                                                                                                        Well, we are in 2016... why not use flexbox?
                                                                                                                                        It's also responsive. Enjoy.




                                                                                                                                        #over{
                                                                                                                                        display:flex;
                                                                                                                                        align-items:center;
                                                                                                                                        justify-content:center;
                                                                                                                                        }

                                                                                                                                        <div id="over">
                                                                                                                                        <img src="http://www.garcard.com/images/garcard_symbol.png">
                                                                                                                                        </div>








                                                                                                                                        share|improve this answer



















                                                                                                                                        • 1





                                                                                                                                          Love css3! Thank you. However, its good to note that this will only work in modern browsers (except IE). All other browsers will have no effect.

                                                                                                                                          – Neel
                                                                                                                                          Jan 9 '17 at 16:44
















                                                                                                                                        2












                                                                                                                                        2








                                                                                                                                        2







                                                                                                                                        Well, we are in 2016... why not use flexbox?
                                                                                                                                        It's also responsive. Enjoy.




                                                                                                                                        #over{
                                                                                                                                        display:flex;
                                                                                                                                        align-items:center;
                                                                                                                                        justify-content:center;
                                                                                                                                        }

                                                                                                                                        <div id="over">
                                                                                                                                        <img src="http://www.garcard.com/images/garcard_symbol.png">
                                                                                                                                        </div>








                                                                                                                                        share|improve this answer













                                                                                                                                        Well, we are in 2016... why not use flexbox?
                                                                                                                                        It's also responsive. Enjoy.




                                                                                                                                        #over{
                                                                                                                                        display:flex;
                                                                                                                                        align-items:center;
                                                                                                                                        justify-content:center;
                                                                                                                                        }

                                                                                                                                        <div id="over">
                                                                                                                                        <img src="http://www.garcard.com/images/garcard_symbol.png">
                                                                                                                                        </div>








                                                                                                                                        #over{
                                                                                                                                        display:flex;
                                                                                                                                        align-items:center;
                                                                                                                                        justify-content:center;
                                                                                                                                        }

                                                                                                                                        <div id="over">
                                                                                                                                        <img src="http://www.garcard.com/images/garcard_symbol.png">
                                                                                                                                        </div>





                                                                                                                                        #over{
                                                                                                                                        display:flex;
                                                                                                                                        align-items:center;
                                                                                                                                        justify-content:center;
                                                                                                                                        }

                                                                                                                                        <div id="over">
                                                                                                                                        <img src="http://www.garcard.com/images/garcard_symbol.png">
                                                                                                                                        </div>






                                                                                                                                        share|improve this answer












                                                                                                                                        share|improve this answer



                                                                                                                                        share|improve this answer










                                                                                                                                        answered Nov 17 '16 at 14:00









                                                                                                                                        GabMicGabMic

                                                                                                                                        844722




                                                                                                                                        844722








                                                                                                                                        • 1





                                                                                                                                          Love css3! Thank you. However, its good to note that this will only work in modern browsers (except IE). All other browsers will have no effect.

                                                                                                                                          – Neel
                                                                                                                                          Jan 9 '17 at 16:44
















                                                                                                                                        • 1





                                                                                                                                          Love css3! Thank you. However, its good to note that this will only work in modern browsers (except IE). All other browsers will have no effect.

                                                                                                                                          – Neel
                                                                                                                                          Jan 9 '17 at 16:44










                                                                                                                                        1




                                                                                                                                        1





                                                                                                                                        Love css3! Thank you. However, its good to note that this will only work in modern browsers (except IE). All other browsers will have no effect.

                                                                                                                                        – Neel
                                                                                                                                        Jan 9 '17 at 16:44







                                                                                                                                        Love css3! Thank you. However, its good to note that this will only work in modern browsers (except IE). All other browsers will have no effect.

                                                                                                                                        – Neel
                                                                                                                                        Jan 9 '17 at 16:44













                                                                                                                                        2














                                                                                                                                        this did the trick for me.



                                                                                                                                        <div class="CenterImage">
                                                                                                                                        <asp:Image ID="BrandImage" runat="server" />
                                                                                                                                        </div>


                                                                                                                                        'Note: do not have a css class assocaited to 'BrandImage' in this case



                                                                                                                                        CSS:



                                                                                                                                        .CenterImage {
                                                                                                                                        position:absolute;
                                                                                                                                        width:100%;
                                                                                                                                        height:100%
                                                                                                                                        }

                                                                                                                                        .CenterImage img {
                                                                                                                                        margin: 0 auto;
                                                                                                                                        display: block;
                                                                                                                                        }





                                                                                                                                        share|improve this answer




























                                                                                                                                          2














                                                                                                                                          this did the trick for me.



                                                                                                                                          <div class="CenterImage">
                                                                                                                                          <asp:Image ID="BrandImage" runat="server" />
                                                                                                                                          </div>


                                                                                                                                          'Note: do not have a css class assocaited to 'BrandImage' in this case



                                                                                                                                          CSS:



                                                                                                                                          .CenterImage {
                                                                                                                                          position:absolute;
                                                                                                                                          width:100%;
                                                                                                                                          height:100%
                                                                                                                                          }

                                                                                                                                          .CenterImage img {
                                                                                                                                          margin: 0 auto;
                                                                                                                                          display: block;
                                                                                                                                          }





                                                                                                                                          share|improve this answer


























                                                                                                                                            2












                                                                                                                                            2








                                                                                                                                            2







                                                                                                                                            this did the trick for me.



                                                                                                                                            <div class="CenterImage">
                                                                                                                                            <asp:Image ID="BrandImage" runat="server" />
                                                                                                                                            </div>


                                                                                                                                            'Note: do not have a css class assocaited to 'BrandImage' in this case



                                                                                                                                            CSS:



                                                                                                                                            .CenterImage {
                                                                                                                                            position:absolute;
                                                                                                                                            width:100%;
                                                                                                                                            height:100%
                                                                                                                                            }

                                                                                                                                            .CenterImage img {
                                                                                                                                            margin: 0 auto;
                                                                                                                                            display: block;
                                                                                                                                            }





                                                                                                                                            share|improve this answer













                                                                                                                                            this did the trick for me.



                                                                                                                                            <div class="CenterImage">
                                                                                                                                            <asp:Image ID="BrandImage" runat="server" />
                                                                                                                                            </div>


                                                                                                                                            'Note: do not have a css class assocaited to 'BrandImage' in this case



                                                                                                                                            CSS:



                                                                                                                                            .CenterImage {
                                                                                                                                            position:absolute;
                                                                                                                                            width:100%;
                                                                                                                                            height:100%
                                                                                                                                            }

                                                                                                                                            .CenterImage img {
                                                                                                                                            margin: 0 auto;
                                                                                                                                            display: block;
                                                                                                                                            }






                                                                                                                                            share|improve this answer












                                                                                                                                            share|improve this answer



                                                                                                                                            share|improve this answer










                                                                                                                                            answered Jun 22 '17 at 9:34









                                                                                                                                            julian9876julian9876

                                                                                                                                            4118




                                                                                                                                            4118























                                                                                                                                                1














                                                                                                                                                Use positioning. The following worked for me...



                                                                                                                                                With zoom to the center of the image (image fills the div):



                                                                                                                                                div{
                                                                                                                                                display:block;
                                                                                                                                                overflow:hidden;
                                                                                                                                                width: 70px;
                                                                                                                                                height: 70px;
                                                                                                                                                position: relative;
                                                                                                                                                }
                                                                                                                                                div img{
                                                                                                                                                min-width: 70px;
                                                                                                                                                min-height: 70px;
                                                                                                                                                max-width: 250%;
                                                                                                                                                max-height: 250%;
                                                                                                                                                top: -50%;
                                                                                                                                                left: -50%;
                                                                                                                                                bottom: -50%;
                                                                                                                                                right: -50%;
                                                                                                                                                position: absolute;
                                                                                                                                                }


                                                                                                                                                Without zoom to the center of the image (image does not fill the div):



                                                                                                                                                   div{
                                                                                                                                                display:block;
                                                                                                                                                overflow:hidden;
                                                                                                                                                width: 100px;
                                                                                                                                                height: 100px;
                                                                                                                                                position: relative;
                                                                                                                                                }
                                                                                                                                                div img{
                                                                                                                                                width: 70px;
                                                                                                                                                height: 70px;
                                                                                                                                                top: 50%;
                                                                                                                                                left: 50%;
                                                                                                                                                bottom: 50%;
                                                                                                                                                right: 50%;
                                                                                                                                                position: absolute;
                                                                                                                                                }





                                                                                                                                                share|improve this answer




























                                                                                                                                                  1














                                                                                                                                                  Use positioning. The following worked for me...



                                                                                                                                                  With zoom to the center of the image (image fills the div):



                                                                                                                                                  div{
                                                                                                                                                  display:block;
                                                                                                                                                  overflow:hidden;
                                                                                                                                                  width: 70px;
                                                                                                                                                  height: 70px;
                                                                                                                                                  position: relative;
                                                                                                                                                  }
                                                                                                                                                  div img{
                                                                                                                                                  min-width: 70px;
                                                                                                                                                  min-height: 70px;
                                                                                                                                                  max-width: 250%;
                                                                                                                                                  max-height: 250%;
                                                                                                                                                  top: -50%;
                                                                                                                                                  left: -50%;
                                                                                                                                                  bottom: -50%;
                                                                                                                                                  right: -50%;
                                                                                                                                                  position: absolute;
                                                                                                                                                  }


                                                                                                                                                  Without zoom to the center of the image (image does not fill the div):



                                                                                                                                                     div{
                                                                                                                                                  display:block;
                                                                                                                                                  overflow:hidden;
                                                                                                                                                  width: 100px;
                                                                                                                                                  height: 100px;
                                                                                                                                                  position: relative;
                                                                                                                                                  }
                                                                                                                                                  div img{
                                                                                                                                                  width: 70px;
                                                                                                                                                  height: 70px;
                                                                                                                                                  top: 50%;
                                                                                                                                                  left: 50%;
                                                                                                                                                  bottom: 50%;
                                                                                                                                                  right: 50%;
                                                                                                                                                  position: absolute;
                                                                                                                                                  }





                                                                                                                                                  share|improve this answer


























                                                                                                                                                    1












                                                                                                                                                    1








                                                                                                                                                    1







                                                                                                                                                    Use positioning. The following worked for me...



                                                                                                                                                    With zoom to the center of the image (image fills the div):



                                                                                                                                                    div{
                                                                                                                                                    display:block;
                                                                                                                                                    overflow:hidden;
                                                                                                                                                    width: 70px;
                                                                                                                                                    height: 70px;
                                                                                                                                                    position: relative;
                                                                                                                                                    }
                                                                                                                                                    div img{
                                                                                                                                                    min-width: 70px;
                                                                                                                                                    min-height: 70px;
                                                                                                                                                    max-width: 250%;
                                                                                                                                                    max-height: 250%;
                                                                                                                                                    top: -50%;
                                                                                                                                                    left: -50%;
                                                                                                                                                    bottom: -50%;
                                                                                                                                                    right: -50%;
                                                                                                                                                    position: absolute;
                                                                                                                                                    }


                                                                                                                                                    Without zoom to the center of the image (image does not fill the div):



                                                                                                                                                       div{
                                                                                                                                                    display:block;
                                                                                                                                                    overflow:hidden;
                                                                                                                                                    width: 100px;
                                                                                                                                                    height: 100px;
                                                                                                                                                    position: relative;
                                                                                                                                                    }
                                                                                                                                                    div img{
                                                                                                                                                    width: 70px;
                                                                                                                                                    height: 70px;
                                                                                                                                                    top: 50%;
                                                                                                                                                    left: 50%;
                                                                                                                                                    bottom: 50%;
                                                                                                                                                    right: 50%;
                                                                                                                                                    position: absolute;
                                                                                                                                                    }





                                                                                                                                                    share|improve this answer













                                                                                                                                                    Use positioning. The following worked for me...



                                                                                                                                                    With zoom to the center of the image (image fills the div):



                                                                                                                                                    div{
                                                                                                                                                    display:block;
                                                                                                                                                    overflow:hidden;
                                                                                                                                                    width: 70px;
                                                                                                                                                    height: 70px;
                                                                                                                                                    position: relative;
                                                                                                                                                    }
                                                                                                                                                    div img{
                                                                                                                                                    min-width: 70px;
                                                                                                                                                    min-height: 70px;
                                                                                                                                                    max-width: 250%;
                                                                                                                                                    max-height: 250%;
                                                                                                                                                    top: -50%;
                                                                                                                                                    left: -50%;
                                                                                                                                                    bottom: -50%;
                                                                                                                                                    right: -50%;
                                                                                                                                                    position: absolute;
                                                                                                                                                    }


                                                                                                                                                    Without zoom to the center of the image (image does not fill the div):



                                                                                                                                                       div{
                                                                                                                                                    display:block;
                                                                                                                                                    overflow:hidden;
                                                                                                                                                    width: 100px;
                                                                                                                                                    height: 100px;
                                                                                                                                                    position: relative;
                                                                                                                                                    }
                                                                                                                                                    div img{
                                                                                                                                                    width: 70px;
                                                                                                                                                    height: 70px;
                                                                                                                                                    top: 50%;
                                                                                                                                                    left: 50%;
                                                                                                                                                    bottom: 50%;
                                                                                                                                                    right: 50%;
                                                                                                                                                    position: absolute;
                                                                                                                                                    }






                                                                                                                                                    share|improve this answer












                                                                                                                                                    share|improve this answer



                                                                                                                                                    share|improve this answer










                                                                                                                                                    answered Mar 24 '16 at 8:38









                                                                                                                                                    FinkAvenueFinkAvenue

                                                                                                                                                    624419




                                                                                                                                                    624419























                                                                                                                                                        0














                                                                                                                                                        You can take a look on this solution:



                                                                                                                                                        Centering horizontally and vertically an image in a box



                                                                                                                                                        <style type="text/css">
                                                                                                                                                        .wraptocenter {
                                                                                                                                                        display: table-cell;
                                                                                                                                                        text-align: center;
                                                                                                                                                        vertical-align: middle;
                                                                                                                                                        width: ...;
                                                                                                                                                        height: ...;
                                                                                                                                                        }
                                                                                                                                                        .wraptocenter * {
                                                                                                                                                        vertical-align: middle;
                                                                                                                                                        }
                                                                                                                                                        .wraptocenter {
                                                                                                                                                        display: block;
                                                                                                                                                        }
                                                                                                                                                        .wraptocenter span {
                                                                                                                                                        display: inline-block;
                                                                                                                                                        height: 100%;
                                                                                                                                                        width: 1px;
                                                                                                                                                        }
                                                                                                                                                        </style>
                                                                                                                                                        <!--[if lt IE 8]-->
                                                                                                                                                        <style>
                                                                                                                                                        .wraptocenter span {
                                                                                                                                                        display: inline-block;
                                                                                                                                                        height: 100%;
                                                                                                                                                        }
                                                                                                                                                        </style>
                                                                                                                                                        <!--[endif]-->

                                                                                                                                                        <div class="wraptocenter"><span></span><img src="..." alt="..."></div>





                                                                                                                                                        share|improve this answer






























                                                                                                                                                          0














                                                                                                                                                          You can take a look on this solution:



                                                                                                                                                          Centering horizontally and vertically an image in a box



                                                                                                                                                          <style type="text/css">
                                                                                                                                                          .wraptocenter {
                                                                                                                                                          display: table-cell;
                                                                                                                                                          text-align: center;
                                                                                                                                                          vertical-align: middle;
                                                                                                                                                          width: ...;
                                                                                                                                                          height: ...;
                                                                                                                                                          }
                                                                                                                                                          .wraptocenter * {
                                                                                                                                                          vertical-align: middle;
                                                                                                                                                          }
                                                                                                                                                          .wraptocenter {
                                                                                                                                                          display: block;
                                                                                                                                                          }
                                                                                                                                                          .wraptocenter span {
                                                                                                                                                          display: inline-block;
                                                                                                                                                          height: 100%;
                                                                                                                                                          width: 1px;
                                                                                                                                                          }
                                                                                                                                                          </style>
                                                                                                                                                          <!--[if lt IE 8]-->
                                                                                                                                                          <style>
                                                                                                                                                          .wraptocenter span {
                                                                                                                                                          display: inline-block;
                                                                                                                                                          height: 100%;
                                                                                                                                                          }
                                                                                                                                                          </style>
                                                                                                                                                          <!--[endif]-->

                                                                                                                                                          <div class="wraptocenter"><span></span><img src="..." alt="..."></div>





                                                                                                                                                          share|improve this answer




























                                                                                                                                                            0












                                                                                                                                                            0








                                                                                                                                                            0







                                                                                                                                                            You can take a look on this solution:



                                                                                                                                                            Centering horizontally and vertically an image in a box



                                                                                                                                                            <style type="text/css">
                                                                                                                                                            .wraptocenter {
                                                                                                                                                            display: table-cell;
                                                                                                                                                            text-align: center;
                                                                                                                                                            vertical-align: middle;
                                                                                                                                                            width: ...;
                                                                                                                                                            height: ...;
                                                                                                                                                            }
                                                                                                                                                            .wraptocenter * {
                                                                                                                                                            vertical-align: middle;
                                                                                                                                                            }
                                                                                                                                                            .wraptocenter {
                                                                                                                                                            display: block;
                                                                                                                                                            }
                                                                                                                                                            .wraptocenter span {
                                                                                                                                                            display: inline-block;
                                                                                                                                                            height: 100%;
                                                                                                                                                            width: 1px;
                                                                                                                                                            }
                                                                                                                                                            </style>
                                                                                                                                                            <!--[if lt IE 8]-->
                                                                                                                                                            <style>
                                                                                                                                                            .wraptocenter span {
                                                                                                                                                            display: inline-block;
                                                                                                                                                            height: 100%;
                                                                                                                                                            }
                                                                                                                                                            </style>
                                                                                                                                                            <!--[endif]-->

                                                                                                                                                            <div class="wraptocenter"><span></span><img src="..." alt="..."></div>





                                                                                                                                                            share|improve this answer















                                                                                                                                                            You can take a look on this solution:



                                                                                                                                                            Centering horizontally and vertically an image in a box



                                                                                                                                                            <style type="text/css">
                                                                                                                                                            .wraptocenter {
                                                                                                                                                            display: table-cell;
                                                                                                                                                            text-align: center;
                                                                                                                                                            vertical-align: middle;
                                                                                                                                                            width: ...;
                                                                                                                                                            height: ...;
                                                                                                                                                            }
                                                                                                                                                            .wraptocenter * {
                                                                                                                                                            vertical-align: middle;
                                                                                                                                                            }
                                                                                                                                                            .wraptocenter {
                                                                                                                                                            display: block;
                                                                                                                                                            }
                                                                                                                                                            .wraptocenter span {
                                                                                                                                                            display: inline-block;
                                                                                                                                                            height: 100%;
                                                                                                                                                            width: 1px;
                                                                                                                                                            }
                                                                                                                                                            </style>
                                                                                                                                                            <!--[if lt IE 8]-->
                                                                                                                                                            <style>
                                                                                                                                                            .wraptocenter span {
                                                                                                                                                            display: inline-block;
                                                                                                                                                            height: 100%;
                                                                                                                                                            }
                                                                                                                                                            </style>
                                                                                                                                                            <!--[endif]-->

                                                                                                                                                            <div class="wraptocenter"><span></span><img src="..." alt="..."></div>






                                                                                                                                                            share|improve this answer














                                                                                                                                                            share|improve this answer



                                                                                                                                                            share|improve this answer








                                                                                                                                                            edited Jul 19 '16 at 19:05









                                                                                                                                                            Mowzer

                                                                                                                                                            5,573743109




                                                                                                                                                            5,573743109










                                                                                                                                                            answered Jul 19 '16 at 19:02









                                                                                                                                                            fpauerfpauer

                                                                                                                                                            32339




                                                                                                                                                            32339























                                                                                                                                                                0














                                                                                                                                                                A simple way would be creating separate styles for both the div and the image and then position them independently. Say if I want to set my image position to 50%, then I would have code which looks like the following....






                                                                                                                                                                #over{
                                                                                                                                                                position:absolute;
                                                                                                                                                                width:100%;
                                                                                                                                                                height:100%;
                                                                                                                                                                }
                                                                                                                                                                #img{
                                                                                                                                                                position:absolute;
                                                                                                                                                                left:50%;
                                                                                                                                                                right:50%;
                                                                                                                                                                }

                                                                                                                                                                <div id="over">
                                                                                                                                                                <img src="img.png" id="img">
                                                                                                                                                                </div>








                                                                                                                                                                share|improve this answer


























                                                                                                                                                                • Just tell me if it works with all kinds of browsers, even though this is a basic thing that every browser must support (otherwise don't call it a browser)

                                                                                                                                                                  – KSJ10
                                                                                                                                                                  Nov 21 '16 at 17:00
















                                                                                                                                                                0














                                                                                                                                                                A simple way would be creating separate styles for both the div and the image and then position them independently. Say if I want to set my image position to 50%, then I would have code which looks like the following....






                                                                                                                                                                #over{
                                                                                                                                                                position:absolute;
                                                                                                                                                                width:100%;
                                                                                                                                                                height:100%;
                                                                                                                                                                }
                                                                                                                                                                #img{
                                                                                                                                                                position:absolute;
                                                                                                                                                                left:50%;
                                                                                                                                                                right:50%;
                                                                                                                                                                }

                                                                                                                                                                <div id="over">
                                                                                                                                                                <img src="img.png" id="img">
                                                                                                                                                                </div>








                                                                                                                                                                share|improve this answer


























                                                                                                                                                                • Just tell me if it works with all kinds of browsers, even though this is a basic thing that every browser must support (otherwise don't call it a browser)

                                                                                                                                                                  – KSJ10
                                                                                                                                                                  Nov 21 '16 at 17:00














                                                                                                                                                                0












                                                                                                                                                                0








                                                                                                                                                                0







                                                                                                                                                                A simple way would be creating separate styles for both the div and the image and then position them independently. Say if I want to set my image position to 50%, then I would have code which looks like the following....






                                                                                                                                                                #over{
                                                                                                                                                                position:absolute;
                                                                                                                                                                width:100%;
                                                                                                                                                                height:100%;
                                                                                                                                                                }
                                                                                                                                                                #img{
                                                                                                                                                                position:absolute;
                                                                                                                                                                left:50%;
                                                                                                                                                                right:50%;
                                                                                                                                                                }

                                                                                                                                                                <div id="over">
                                                                                                                                                                <img src="img.png" id="img">
                                                                                                                                                                </div>








                                                                                                                                                                share|improve this answer















                                                                                                                                                                A simple way would be creating separate styles for both the div and the image and then position them independently. Say if I want to set my image position to 50%, then I would have code which looks like the following....






                                                                                                                                                                #over{
                                                                                                                                                                position:absolute;
                                                                                                                                                                width:100%;
                                                                                                                                                                height:100%;
                                                                                                                                                                }
                                                                                                                                                                #img{
                                                                                                                                                                position:absolute;
                                                                                                                                                                left:50%;
                                                                                                                                                                right:50%;
                                                                                                                                                                }

                                                                                                                                                                <div id="over">
                                                                                                                                                                <img src="img.png" id="img">
                                                                                                                                                                </div>








                                                                                                                                                                #over{
                                                                                                                                                                position:absolute;
                                                                                                                                                                width:100%;
                                                                                                                                                                height:100%;
                                                                                                                                                                }
                                                                                                                                                                #img{
                                                                                                                                                                position:absolute;
                                                                                                                                                                left:50%;
                                                                                                                                                                right:50%;
                                                                                                                                                                }

                                                                                                                                                                <div id="over">
                                                                                                                                                                <img src="img.png" id="img">
                                                                                                                                                                </div>





                                                                                                                                                                #over{
                                                                                                                                                                position:absolute;
                                                                                                                                                                width:100%;
                                                                                                                                                                height:100%;
                                                                                                                                                                }
                                                                                                                                                                #img{
                                                                                                                                                                position:absolute;
                                                                                                                                                                left:50%;
                                                                                                                                                                right:50%;
                                                                                                                                                                }

                                                                                                                                                                <div id="over">
                                                                                                                                                                <img src="img.png" id="img">
                                                                                                                                                                </div>






                                                                                                                                                                share|improve this answer














                                                                                                                                                                share|improve this answer



                                                                                                                                                                share|improve this answer








                                                                                                                                                                edited Dec 4 '16 at 8:57

























                                                                                                                                                                answered Nov 21 '16 at 16:54









                                                                                                                                                                KSJ10KSJ10

                                                                                                                                                                438




                                                                                                                                                                438













                                                                                                                                                                • Just tell me if it works with all kinds of browsers, even though this is a basic thing that every browser must support (otherwise don't call it a browser)

                                                                                                                                                                  – KSJ10
                                                                                                                                                                  Nov 21 '16 at 17:00



















                                                                                                                                                                • Just tell me if it works with all kinds of browsers, even though this is a basic thing that every browser must support (otherwise don't call it a browser)

                                                                                                                                                                  – KSJ10
                                                                                                                                                                  Nov 21 '16 at 17:00

















                                                                                                                                                                Just tell me if it works with all kinds of browsers, even though this is a basic thing that every browser must support (otherwise don't call it a browser)

                                                                                                                                                                – KSJ10
                                                                                                                                                                Nov 21 '16 at 17:00





                                                                                                                                                                Just tell me if it works with all kinds of browsers, even though this is a basic thing that every browser must support (otherwise don't call it a browser)

                                                                                                                                                                – KSJ10
                                                                                                                                                                Nov 21 '16 at 17:00











                                                                                                                                                                0














                                                                                                                                                                #over {
                                                                                                                                                                display: table-cell;
                                                                                                                                                                vertical-align: middle;
                                                                                                                                                                text-align: center;
                                                                                                                                                                height: 100px;
                                                                                                                                                                }


                                                                                                                                                                Modify height value for your need.






                                                                                                                                                                share|improve this answer




























                                                                                                                                                                  0














                                                                                                                                                                  #over {
                                                                                                                                                                  display: table-cell;
                                                                                                                                                                  vertical-align: middle;
                                                                                                                                                                  text-align: center;
                                                                                                                                                                  height: 100px;
                                                                                                                                                                  }


                                                                                                                                                                  Modify height value for your need.






                                                                                                                                                                  share|improve this answer


























                                                                                                                                                                    0












                                                                                                                                                                    0








                                                                                                                                                                    0







                                                                                                                                                                    #over {
                                                                                                                                                                    display: table-cell;
                                                                                                                                                                    vertical-align: middle;
                                                                                                                                                                    text-align: center;
                                                                                                                                                                    height: 100px;
                                                                                                                                                                    }


                                                                                                                                                                    Modify height value for your need.






                                                                                                                                                                    share|improve this answer













                                                                                                                                                                    #over {
                                                                                                                                                                    display: table-cell;
                                                                                                                                                                    vertical-align: middle;
                                                                                                                                                                    text-align: center;
                                                                                                                                                                    height: 100px;
                                                                                                                                                                    }


                                                                                                                                                                    Modify height value for your need.







                                                                                                                                                                    share|improve this answer












                                                                                                                                                                    share|improve this answer



                                                                                                                                                                    share|improve this answer










                                                                                                                                                                    answered Jul 24 '17 at 2:33









                                                                                                                                                                    Terry LinTerry Lin

                                                                                                                                                                    1,5361319




                                                                                                                                                                    1,5361319























                                                                                                                                                                        0














                                                                                                                                                                        This should work.



                                                                                                                                                                        IMPORTANT FOR TEST: To Run code snippet click left button RUN code snippet, then right link Full page






                                                                                                                                                                        #fader{
                                                                                                                                                                        position:fixed;z-index: 10;
                                                                                                                                                                        top:0;right:0;bottom:0;left:0;
                                                                                                                                                                        opacity: 0.8;background: black;
                                                                                                                                                                        width:100%;height:100%;
                                                                                                                                                                        text-align: center;
                                                                                                                                                                        }
                                                                                                                                                                        .faders{display:inline-block;height:100%;vertical-align:middle;}
                                                                                                                                                                        .faderi{display:inline-block;vertical-align:middle;}

                                                                                                                                                                        <div id="fader">
                                                                                                                                                                        <span class="faders"></span>
                                                                                                                                                                        <img class="faderi" src="https://i.stack.imgur.com/qHF2K.png" />
                                                                                                                                                                        </div>








                                                                                                                                                                        share|improve this answer






























                                                                                                                                                                          0














                                                                                                                                                                          This should work.



                                                                                                                                                                          IMPORTANT FOR TEST: To Run code snippet click left button RUN code snippet, then right link Full page






                                                                                                                                                                          #fader{
                                                                                                                                                                          position:fixed;z-index: 10;
                                                                                                                                                                          top:0;right:0;bottom:0;left:0;
                                                                                                                                                                          opacity: 0.8;background: black;
                                                                                                                                                                          width:100%;height:100%;
                                                                                                                                                                          text-align: center;
                                                                                                                                                                          }
                                                                                                                                                                          .faders{display:inline-block;height:100%;vertical-align:middle;}
                                                                                                                                                                          .faderi{display:inline-block;vertical-align:middle;}

                                                                                                                                                                          <div id="fader">
                                                                                                                                                                          <span class="faders"></span>
                                                                                                                                                                          <img class="faderi" src="https://i.stack.imgur.com/qHF2K.png" />
                                                                                                                                                                          </div>








                                                                                                                                                                          share|improve this answer




























                                                                                                                                                                            0












                                                                                                                                                                            0








                                                                                                                                                                            0







                                                                                                                                                                            This should work.



                                                                                                                                                                            IMPORTANT FOR TEST: To Run code snippet click left button RUN code snippet, then right link Full page






                                                                                                                                                                            #fader{
                                                                                                                                                                            position:fixed;z-index: 10;
                                                                                                                                                                            top:0;right:0;bottom:0;left:0;
                                                                                                                                                                            opacity: 0.8;background: black;
                                                                                                                                                                            width:100%;height:100%;
                                                                                                                                                                            text-align: center;
                                                                                                                                                                            }
                                                                                                                                                                            .faders{display:inline-block;height:100%;vertical-align:middle;}
                                                                                                                                                                            .faderi{display:inline-block;vertical-align:middle;}

                                                                                                                                                                            <div id="fader">
                                                                                                                                                                            <span class="faders"></span>
                                                                                                                                                                            <img class="faderi" src="https://i.stack.imgur.com/qHF2K.png" />
                                                                                                                                                                            </div>








                                                                                                                                                                            share|improve this answer















                                                                                                                                                                            This should work.



                                                                                                                                                                            IMPORTANT FOR TEST: To Run code snippet click left button RUN code snippet, then right link Full page






                                                                                                                                                                            #fader{
                                                                                                                                                                            position:fixed;z-index: 10;
                                                                                                                                                                            top:0;right:0;bottom:0;left:0;
                                                                                                                                                                            opacity: 0.8;background: black;
                                                                                                                                                                            width:100%;height:100%;
                                                                                                                                                                            text-align: center;
                                                                                                                                                                            }
                                                                                                                                                                            .faders{display:inline-block;height:100%;vertical-align:middle;}
                                                                                                                                                                            .faderi{display:inline-block;vertical-align:middle;}

                                                                                                                                                                            <div id="fader">
                                                                                                                                                                            <span class="faders"></span>
                                                                                                                                                                            <img class="faderi" src="https://i.stack.imgur.com/qHF2K.png" />
                                                                                                                                                                            </div>








                                                                                                                                                                            #fader{
                                                                                                                                                                            position:fixed;z-index: 10;
                                                                                                                                                                            top:0;right:0;bottom:0;left:0;
                                                                                                                                                                            opacity: 0.8;background: black;
                                                                                                                                                                            width:100%;height:100%;
                                                                                                                                                                            text-align: center;
                                                                                                                                                                            }
                                                                                                                                                                            .faders{display:inline-block;height:100%;vertical-align:middle;}
                                                                                                                                                                            .faderi{display:inline-block;vertical-align:middle;}

                                                                                                                                                                            <div id="fader">
                                                                                                                                                                            <span class="faders"></span>
                                                                                                                                                                            <img class="faderi" src="https://i.stack.imgur.com/qHF2K.png" />
                                                                                                                                                                            </div>





                                                                                                                                                                            #fader{
                                                                                                                                                                            position:fixed;z-index: 10;
                                                                                                                                                                            top:0;right:0;bottom:0;left:0;
                                                                                                                                                                            opacity: 0.8;background: black;
                                                                                                                                                                            width:100%;height:100%;
                                                                                                                                                                            text-align: center;
                                                                                                                                                                            }
                                                                                                                                                                            .faders{display:inline-block;height:100%;vertical-align:middle;}
                                                                                                                                                                            .faderi{display:inline-block;vertical-align:middle;}

                                                                                                                                                                            <div id="fader">
                                                                                                                                                                            <span class="faders"></span>
                                                                                                                                                                            <img class="faderi" src="https://i.stack.imgur.com/qHF2K.png" />
                                                                                                                                                                            </div>






                                                                                                                                                                            share|improve this answer














                                                                                                                                                                            share|improve this answer



                                                                                                                                                                            share|improve this answer








                                                                                                                                                                            edited Oct 24 '17 at 22:59

























                                                                                                                                                                            answered Oct 24 '17 at 22:53









                                                                                                                                                                            IntactoIntacto

                                                                                                                                                                            1843




                                                                                                                                                                            1843























                                                                                                                                                                                0














                                                                                                                                                                                Use bootstraps align-items and justify-content. See example below:



                                                                                                                                                                                <div class="well" style="align-items:center;justify-content:center;">
                                                                                                                                                                                <img src="img_source" height="50px" width="50px"/>
                                                                                                                                                                                </div>





                                                                                                                                                                                share|improve this answer




























                                                                                                                                                                                  0














                                                                                                                                                                                  Use bootstraps align-items and justify-content. See example below:



                                                                                                                                                                                  <div class="well" style="align-items:center;justify-content:center;">
                                                                                                                                                                                  <img src="img_source" height="50px" width="50px"/>
                                                                                                                                                                                  </div>





                                                                                                                                                                                  share|improve this answer


























                                                                                                                                                                                    0












                                                                                                                                                                                    0








                                                                                                                                                                                    0







                                                                                                                                                                                    Use bootstraps align-items and justify-content. See example below:



                                                                                                                                                                                    <div class="well" style="align-items:center;justify-content:center;">
                                                                                                                                                                                    <img src="img_source" height="50px" width="50px"/>
                                                                                                                                                                                    </div>





                                                                                                                                                                                    share|improve this answer













                                                                                                                                                                                    Use bootstraps align-items and justify-content. See example below:



                                                                                                                                                                                    <div class="well" style="align-items:center;justify-content:center;">
                                                                                                                                                                                    <img src="img_source" height="50px" width="50px"/>
                                                                                                                                                                                    </div>






                                                                                                                                                                                    share|improve this answer












                                                                                                                                                                                    share|improve this answer



                                                                                                                                                                                    share|improve this answer










                                                                                                                                                                                    answered Feb 20 '18 at 14:18









                                                                                                                                                                                    MwizakMwizak

                                                                                                                                                                                    1,79321116




                                                                                                                                                                                    1,79321116























                                                                                                                                                                                        0














                                                                                                                                                                                        I add some more properties to the CSS. Like so:



                                                                                                                                                                                        div#over {
                                                                                                                                                                                        width: 100%;
                                                                                                                                                                                        height: 100%;
                                                                                                                                                                                        display: flex;
                                                                                                                                                                                        justify-content: center;
                                                                                                                                                                                        align-items: center;
                                                                                                                                                                                        -ms-align-items: center;
                                                                                                                                                                                        display: -webkit-flex;
                                                                                                                                                                                        display: -ms-flex;
                                                                                                                                                                                        display: flex;
                                                                                                                                                                                        }





                                                                                                                                                                                        share|improve this answer




























                                                                                                                                                                                          0














                                                                                                                                                                                          I add some more properties to the CSS. Like so:



                                                                                                                                                                                          div#over {
                                                                                                                                                                                          width: 100%;
                                                                                                                                                                                          height: 100%;
                                                                                                                                                                                          display: flex;
                                                                                                                                                                                          justify-content: center;
                                                                                                                                                                                          align-items: center;
                                                                                                                                                                                          -ms-align-items: center;
                                                                                                                                                                                          display: -webkit-flex;
                                                                                                                                                                                          display: -ms-flex;
                                                                                                                                                                                          display: flex;
                                                                                                                                                                                          }





                                                                                                                                                                                          share|improve this answer


























                                                                                                                                                                                            0












                                                                                                                                                                                            0








                                                                                                                                                                                            0







                                                                                                                                                                                            I add some more properties to the CSS. Like so:



                                                                                                                                                                                            div#over {
                                                                                                                                                                                            width: 100%;
                                                                                                                                                                                            height: 100%;
                                                                                                                                                                                            display: flex;
                                                                                                                                                                                            justify-content: center;
                                                                                                                                                                                            align-items: center;
                                                                                                                                                                                            -ms-align-items: center;
                                                                                                                                                                                            display: -webkit-flex;
                                                                                                                                                                                            display: -ms-flex;
                                                                                                                                                                                            display: flex;
                                                                                                                                                                                            }





                                                                                                                                                                                            share|improve this answer













                                                                                                                                                                                            I add some more properties to the CSS. Like so:



                                                                                                                                                                                            div#over {
                                                                                                                                                                                            width: 100%;
                                                                                                                                                                                            height: 100%;
                                                                                                                                                                                            display: flex;
                                                                                                                                                                                            justify-content: center;
                                                                                                                                                                                            align-items: center;
                                                                                                                                                                                            -ms-align-items: center;
                                                                                                                                                                                            display: -webkit-flex;
                                                                                                                                                                                            display: -ms-flex;
                                                                                                                                                                                            display: flex;
                                                                                                                                                                                            }






                                                                                                                                                                                            share|improve this answer












                                                                                                                                                                                            share|improve this answer



                                                                                                                                                                                            share|improve this answer










                                                                                                                                                                                            answered Nov 23 '18 at 10:35









                                                                                                                                                                                            KramerKramer

                                                                                                                                                                                            191114




                                                                                                                                                                                            191114

















                                                                                                                                                                                                protected by Tushar Gupta Oct 15 '14 at 17:37



                                                                                                                                                                                                Thank you for your interest in this question.
                                                                                                                                                                                                Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                                                                                                                                                                                Would you like to answer one of these unanswered questions instead?



                                                                                                                                                                                                Popular posts from this blog

                                                                                                                                                                                                If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                                                                                                                                                                                                Alcedinidae

                                                                                                                                                                                                Can an atomic nucleus contain both particles and antiparticles? [duplicate]