Home>Article>Web Front-end> Solution to invalid margin:0 auto in css

Solution to invalid margin:0 auto in css

黄舟
黄舟 Original
2017-07-21 13:41:34 4893browse

Margin:0 auto invalid solution in css

111111111

The width of div1 is the screen width, the width of div2 depends on the content size and is centered with div1, but the width of div2 is still div1 after I set it to auto. 100% width, why is this? I've been researching all night and still can't figure it out. I hope someone can give me an answer?

Put a div3 outside div2, and set div3 to be horizontally centered, that is, text-align:center; div2 is set to be an inline element, that is, display:inline; and that's it.

Solution to invalid margin:0 auto in css

div defaults to block-level elements. Block-level elements all occupy a line by themselves, and the width defaults to 100%.

When running this code under IE8, it is not centered. Is there any other solution besides setting text-align:center on the body?

   
没有居中。。

Personal test IE8 has no problem with centering

Solution to invalid margin:0 auto in css

If you want the text to be centered, just set .tcenter{text-align:center}

margin:0 auto; is used to center the div, not the text.

The above is the detailed content of Solution to invalid margin:0 auto in css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn