[英]Make a div take up the entire width of the page
我正在一個小型網站上工作。 為了更易於閱讀,我將網站的所有內容都放在中間。
body {
width: 500px;
margin-left: auto;
margin-right: auto;
}
問題在於div遵循此規則,並且僅位於最中央。
在頁腳類中,我嘗試通過將邊距和寬度設置為100%來重置它們,但這沒有用。
.footer {
width: 100%;
margin-left: 0%;
margin-right: 100%;
}
無需將整個body
設置為500px寬度,而是為主要內容創建一個div
,然后將頁腳放在下面。
#content { width: 500px; margin-left: auto; margin-right: auto; }
<body> <div id="content"> <!-- Main page content here --> </div> <div id="footer"> <!-- Footer content here --> </div> </body>
嘗試將CSS從您的身體移到一個包含的<div>
,並將所有內容放在其中,並使頁腳位於包含的<div>
,如果元素是唯一的,則使用id
s not class
例如
HTML:
<body>
<div id="mainContent">
<!-- Main site stuff here -->
</div>
<div id="footer">
<!-- footer info here-->
</div>
CSS:
body{
/*No CSS*/
}
#mainContent{
width: 500px;
margin-left: auto;
margin-right: auto;
}
#footer {
width: 100%;
margin: 0;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.