Vertically center in viewport using CSS

后端 未结 4 713
一生所求
一生所求 2020-12-06 00:14

I am looking to vertically center a

in the viewport (browser window) without resorting to Javascript (pure HTML and CSS only). I have several const
4条回答
  •  南笙
    南笙 (楼主)
    2020-12-06 00:43

    The easiest way is not to use a div - use a table with one row and one cell. Vertical alignment is woefully unsupported in CSS and you will find yourself coding up the wall and across the ceiling to accomplish it.

    I understand the semantic argument against what I have just proposed - I am a proponent of semantic markup in most cases. However I also believe in using the right tool for the right job. I believe it is best to sacrifice a little purity in this case for a simple solution that will work.

提交回复
热议问题