css中的垂直置中,不同於在Table中

來源:互聯網
上載者:User

垂直置中對錶格來說是小菜一碟,只需指定儲存格為vertical-align: middle即可,
但這在css布局中不管用。假設你將一個導覽功能表的高度設為2em,
然後在css中指定垂直對齊的規則,文字還是會被排到盒的頂部,根本沒有什麼區別。
要解決這一問題,只需將盒的行高設為與盒的高度相同即可,
以這個例子來說,盒高2em,那麼只需在css中再加入一條:line-height: 2em 就可實現垂直

相關文章

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.