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

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

老師,只在footer設置clear:both,mainbody中不設置overflow:hidden也可以的啊,這是為什么呢

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>無標題文檔</title>

<style type="text/css">

* { margin: 0; padding: 0; }

#wrap { width: 960px; margin: 0 auto; background: red; }

#header { width: 100%; background: black; }

#mainbody { width: 100%; background: yellow;}

#left{width:800px; ?background:green;float:left;}

#right{width:140px; height:300px; background:blue;float:right;}

#footer{width:100%;background:pink;clear:both;}


</style>

</head>


<body>

<div id="wrap">

? <div id="header">頭部</div>

? <div id="mainbody">

? ? <div id="left">左邊</div>

? ? <div id="right">右邊</div>

? </div>

? <div id="footer">版權部分</div>

</div>

</body>

</html>


正在回答

3 回答

你在mainbody中不設置overflow:hidden,由于它的兩個子div都浮動了,#mainbody本身就感知不到高度了。具體視角效果,你可以設置#left或#right的高度后,你觀察一下就明白了。


2 回復 有任何疑惑可以回復我~

你的代碼也沒有錯,但是有沒有發現#mainbody不見了呢,overflow:hidden是設置#mainbody這個層不受#left和#right浮動的影響

0 回復 有任何疑惑可以回復我~
#mainbody?{?width:?100%;?background:?yellow;}
#left{width:800px;??background:green;float:left;}
#right{width:140px;?height:300px;?background:blue;float:right;}
#footer{width:100%;background:pink;clear:both;}

我這樣設置之后好像沒什么變化,還是不怎么明白,請老師指出來,

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
網頁布局基礎
  • 參與學習       214663    人
  • 解答問題       1833    個

讓你精通CSS中三大定位機制,徹底掌握網頁布局的相關知識

進入課程

老師,只在footer設置clear:both,mainbody中不設置overflow:hidden也可以的啊,這是為什么呢

我要回答 關注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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