課程
/前端開發
/HTML/CSS
/網頁布局基礎
另外一種方法,對right做float:right,然后對后面foot做clear:both得到的效果感覺差不多,但是mainbody顏色自己換了。這是為什么?
2016-05-09
源自:網頁布局基礎 3-5
正在回答
藍色是wrap的背景色,對footer使用clear:both;清除了上面right的浮動,但是left和right浮動之后脫離文檔流,無法撐起mianbody,所以看不到mianbody的背景色,之間顯示出了wrap的背景色
C0EEC3F7BBAA
<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <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:0px; padding:0px; ??} ??.floatleft{ ?? float:left; ??} ??.floatright{ ?? float:right; ??} ??.floatclear{ ?? clear:both; ??} ??#warp{ background:#CCC; width:960px; margin:0px?auto; ??} ??#header{ ?? background:red; ??} ??#mainbody{ ?? background:green; ??} ??#footer{ ?? background:pink; text-align:center; ??} ??.box{ background:yellow; ??} </style> </head> <body> <div?id="warp"> ??<div?id="header">頭部</div> ??<div?id="mainbody"> ?? <div?class="box?floatleft"> ??????left ????</div> ?? <div?class="box?floatright"> ??????right ????</div> ??</div> ??<div?class="floatclear"></div> ??<div?id="footer">版權部分</div> </div> </body> </html>
vaneX
哦,還對left做了float:left。
舉報
讓你精通CSS中三大定位機制,徹底掌握網頁布局的相關知識
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-06-11
藍色是wrap的背景色,對footer使用clear:both;清除了上面right的浮動,但是left和right浮動之后脫離文檔流,無法撐起mianbody,所以看不到mianbody的背景色,之間顯示出了wrap的背景色
2016-05-09
<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <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:0px; padding:0px; ??} ??.floatleft{ ?? float:left; ??} ??.floatright{ ?? float:right; ??} ??.floatclear{ ?? clear:both; ??} ??#warp{ background:#CCC; width:960px; margin:0px?auto; ??} ??#header{ ?? background:red; ??} ??#mainbody{ ?? background:green; ??} ??#footer{ ?? background:pink; text-align:center; ??} ??.box{ background:yellow; ??} </style> </head> <body> <div?id="warp"> ??<div?id="header">頭部</div> ??<div?id="mainbody"> ?? <div?class="box?floatleft"> ??????left ????</div> ?? <div?class="box?floatright"> ??????right ????</div> ??</div> ??<div?class="floatclear"></div> ??<div?id="footer">版權部分</div> </div> </body> </html>2016-05-09
哦,還對left做了float:left。