WEB標準布局Div + CSS 高度自適應方法

來源:互聯網
上載者:User
自適應高度的問題,採用 Div + CSS 進行三列或二列布局時,由於事先不知道具體高度,只能根據內容的增減自適應高度,很多情況下要求兩列(或三列)Div的高度相同,以前用 Table 很容易實現,但採用 Div + CSS 就顯得比較麻煩了。一般的做法,大都採用背景圖填充或 JS 指令碼控制的方法使各Div高度相同,這裡看到一個解決方案,記錄如下:

它主要是採用“隱藏容器溢出”和“正內補丁”和“負外補丁”結合方式,範例程式碼如下:

<!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>Div + CSS Example, Wayhome's Blog</title>
<style type="text/css">
<!--
#wrap{overflow:hidden;}
#sidebar_left,#sidebar_right{padding-bottom:100000px;margin-bottom:-100000px;}
-->
</style></head>
<body>
<div id="wrap" style="width:300px; background:#FFFF00;">
<div id="sidebar_left" style="float:left;width:100px; background:#FF0000;">Left</div>
<div id="sidebar_mid" style="float:left;width:100px; background:#666;">
Middle<br />
Middle<br />
Middle<br />
Middle<br />
Middle<br />
Middle<br />
Middle<br />
Middle<br />
Middle<br />
</div>
<div id="sidebar_right" style="float:right;width:100px; background:#0000FF;">Right</div>
</div>
</body>
</html>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.