Thursday 17 November 2016

one simple problem-----how to put text in center of div vertically and horizontally

I always meet this question, how to put text in center of div vertically and horizontally.

                     to


first way,

              text-align: center;
              line-height: 50px;(depending on the div height)


Here the line-height is a little bit confused, in Chinese, it is called ''行高''
but i feel it is not so right.
http://www.w3schools.com/cssreF/playit.asp?filename=playcss_line-height&preval=3

this is one website, for understanding it better.


Second way,

                   text-align: center;
                   padding-top: 20px;
                   padding-bottom: 20px;
           

but in this way, you cannot set height again, because padding-top.padding-bottom include height set.

No comments:

Post a Comment