-3
如何居中對齊網頁內容的整個body
?我試過text-align:center
對齊,但失敗!居中對齊網頁
如何居中對齊網頁內容的整個body
?我試過text-align:center
對齊,但失敗!居中對齊網頁
width:900px;
margin:auto;
確保它沒有浮動。
CSS:
div#body {
width:902px; //Or whatever your content width is
margin:0 auto;
padding:0;
}
如何網站看起來像:
<html>
<body>
<div id"body">
...The rest of your content...
</div>
</body>
</html>
您可以使用jQuery也:
$(window).resize(function(){
$('.className').css({
position:'absolute',
left: ($(window).width() - $('.className').outerWidth())/2,
top: ($(window).height() - $('.className').outerHeight())/2
});
});
// To initially run the function:
$(window).resize();
也爲您的教程:http://tutorialzine.com/2010/03/centering-div-vertically-and-horizontally/
樂施會..我缺少'margin:auto'。謝謝我的問題已經解決了。但我不明白爲什麼沒有設置這個網頁居中。 –
因爲默認值是'margin:0'。 :-) – Artfunkel