HTML&CSS——line-height設定成height使得文字置中__HTML

來源:互聯網
上載者:User
首先行高是文字的字元大小和字元上下的邊距決定的,關鍵就是這個上下的邊距是相等的,你可以把行高想象是兩條看不見的水平平行線,而在平行線內,字元與平行線上下的邊距總是相等的,就是垂直置中的意思。而height這個屬性是盒子屬性的高度,盒子並沒有像行高這樣與上下的邊距是相等的要求。而是預設在左上方所以不是行高line-height與文字高height一樣就能讓文字置中,而是應該這樣理解,字元本來就在行高內垂直置中了,只是行高與文字的盒子高度不等,導致不能在盒子裡垂直置中,如果我們把行高line-height與盒子的height設定為一樣大,意思就是行高的平行線與盒子的上下邊重合了,這時字元當然仍是在行高內垂直置中,但也順便在盒子內垂直置中。
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.