亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

如何用CSS進行網頁布局

江老實 Web前端工程師
難度初級
時長22分
學習人數
綜合評分9.60
1991人評價 查看評價
9.8 內容實用
9.6 簡潔易懂
9.4 邏輯清晰
.top{width:100%;height:100px;margin:0;background:#ccc;}
.main{width:100%;height:500px;background:red;}
.left{width:200px;height:500px;float:left;background:blue;}
.right{margin-left:210px;width:100%;height:500px;background:green;position:absolute}
.foot{width:100%;height:150px;background:#F90}
上節視頻,定左右絕對,定左右上0;中間只設高度,不設寬,six,six,six

已采納回答 / qq_杜飛_03761348
他們設置 310 和210 是為了讓效果圖和案例一樣,中間div和兩邊有空白的間距。由于中間的div設置的margin 所以,它的距離是相對于body的距離,你疑問為啥不是和左右兩個div的距離,是因為,左右兩個div由于設置了absolute 脫離了文檔流,也就是相當于相對其他div來說,它類似于透明的空氣一般。

最贊回答 / qq_冇_7
定義了width:100%,就相當于瀏覽器窗口的可視寬度,或者是已定義寬度的body的寬度。不定義寬度的話,塊級元素寬度會自適應。如果不再增加別的樣式,寬度也就相當于100%。在此基礎上,如果為塊級元素增加margin-left?和?margin-right,那么定義了width:100%的塊級元素寬度不變,仍就相當于瀏覽器窗口的可視寬度,或者是已定義寬度的body的寬度。而未定義寬度的塊級元素的寬度會在瀏覽器基可視寬度或者是已定義寬度的body的寬度礎上自動減去magin的值。
.left{ width:200px; height:500px; background:blue; }
.right{ height:500px; background:#9C9;width:100%;margin-left:220px;position:absolute}
為了兼容ie6,左右不用float;右側加絕對定位加寬度自適應即可

最新回答 / 慕萊塢2413426
你的代碼在我這邊可以顯示,參考我的<...code...>
.left{width:200px;height:500px;background-color:blue; float:left;}
.right{height:500px;background-color:green;width:100%;margin-left:210px; position:absolute;}
因為right先加載,所以right用絕對定位position:absolute,left用float浮動;
.top{width:100%;background:#ccc;height:100px;}

.main{width:100%;background:red;height:500px;}

.left{width:200px;background:blue;height:500px;float:left;}

.right{background:#9BCD9B;height:500px;float:right;width:calc(100% - 210px);}

.foot{width:100%;background:#FF7F00;}
.top{height:100px;background:#ccc;}
.main{background:#f00;height:600px;position:relative;overflow:hidden;}父元素定位,overflow隱藏超出的部分
.left{height:600px;width:200px;background:#00f}
.right{height:600px;width:100%;position:absolute;background:#9a9;margin-left:210px;}
.foot{height:100px;background:#aa0;}
.footer{width:960px;height:50px;background:#9F9;margin:600px auto 0 auto;}
0換成auto就能居中了
.top{height:100px;background:#cccccc;}
.main{height:600px;background:#fa0002;}
.left{height:600px;width:33%;background:#0000fe;float:left;}
.right{height:600px;width:65%;background:#9acc99;float:right;}
.foot{height:50px;background:#ff6634;}
為什么學完才59%?
正確代碼:
.top{height:100px; background:#4e4e4e;}
.main{width:100%; height:600px;background:red;margin:0 auto;}
.left{ width:30%;height:600px;background:blue;float:left;}
.right{width:68%;height:600px;background:green;float:right;}
.foot{height:100px; background:#F63;}

最新回答 / 誠小豬
為了更好的看出設置的效果
div是塊級元素,會獨占一行。當div使用浮動以后,就會脫離原有的位置,所以多個浮動元素可以在一行內。
課程須知
1.你需要掌握html+css樣式基礎知識 2.有一定的前端實際開發經驗
老師告訴你能學到什么?
1.掌握網頁布局的相關知識 2.能對不同的網頁進行布局結構劃分 3.掌握固定寬度和自適應寬度的實現方法

微信掃碼,參與3人拼團

微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

友情提示:

您好,此課程屬于遷移課程,您已購買該課程,無需重復購買,感謝您對慕課網的支持!

本次提問將花費2個積分

你的積分不足,無法發表

為什么扣積分?

本次提問將花費2個積分

繼續發表請點擊 "確定"

為什么扣積分?

舉報

0/150
提交
取消