center text in div

后端 未结 3 1912
广开言路
广开言路 2021-01-19 23:27
  

test

3条回答
  •  走了就别回头了
    2021-01-20 00:04

    Do you mean vertical centering, horizontal centering or both?

    Horizontal centering of inline content is easy. Just apply text-align: center to the containing block. Centering horizontally a block within another block with CSS is typically done with:

    #centerMe { margin: 0 auto; }
    

    Note: on IE6 this requires that IE be in "standards compliant" rather than "quirks" mode. To force this always put a DOCTYPE on your HTML document. For example:

    
    

    Vertical centering is much worse.

    You may want to look at Vertical Centering in CSS. This is actually a non-trivial problem. The vertical-align style property you're using only applies to table cells (in a cross-browser backwards compatible way). This would be trivial to do with a table for what it's worth.

提交回复
热议问题