我试图让我的网站居中,我试过将 div 放在 div 中,但我认为这不是正确的做法。有人能告诉我如何拥有 100% 宽度但像 facebook 一样居中吗?提前致谢。
最佳答案
简单使用,例如:
Demo Fiddle
body{
width:100%; /* <--- make the document content the width of the viewport */
text-align:center; /* <--- centre the document content */
margin:0;
}
div{
margin:0 auto; /** <-- align the content to the centre of the document */
width:500px; /** <-- width of your content */
}
关于html - 如何在 css 中正确居中 100% 宽度的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25244098/