Re: [問題] 父div的高度只包含了一個子div

看板Web_Design作者 (罪雲樵)時間16年前 (2009/12/22 12:24), 編輯推噓2(202)
留言4則, 4人參與, 最新討論串2/3 (看更多)
※ 引述《icetreen》之銘言: : <div id="A"> : <div id="B"> : </div> : <div id="C"> : </div> : </div> : 這是我原始想要的三個圖層,但只有B圖層有設height : 結果變成這樣 : ┌─────────────┐ : │A │ : │┌───────────┐│ : ││B ││ : └┴───────────┴┘ : ┌───────────┐ : │C │ : │ │ : └───────────┘ : 我以為父DIV的高度自動會變成所包含所有子DIV的高度,請問一下要加什麼參數嗎? : 這麼基本的問題快把我搞瘋了@@ : 謝謝>< : ※ 編輯: icetreen 來自: 220.229.80.88 (12/22 12:11) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "" rel="nofollow">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="" rel="nofollow">http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>⊥ꢙ憿霁隇隞똼/title> <style type="text/css"> <!-- .style1 { color: #FF0000; position:absolute; border:1px #FF0000 solid; height:200px; width:200px; left:100px; top:100px; } .style2 { color: #0000FF; position:relative; border:1px #00FF00 solid; height:100px; } .style3 { color: #FF00FF; position:relative; border:1px #00FF00 solid; height:auto; } --> </style> </head> <body> <div class="style1"> aaaaaaaaaaaaaaaaaa <div class="style2"> bbbbbbbbbbbbbbbbbbbb </div> <div class="style3"> cccccccccccccccccccccccc </div> </div> </body> </html> 以上!自已玩玩看囉!我用dw寫的。 -- 朝叩朱門吃餘餐 嗟來冷眼有德顏 歸途踏盡金磚路 漫天彩霞不用錢 吾乃…富貴乞丐-花爵百鍊生 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.32.171.66

12/22 13:36, , 1F
跟position完全沒關係吧...
12/22 13:36, 1F

12/22 13:44, , 2F
所以答案是height = auto嗎?
12/22 13:44, 2F

12/22 15:44, , 3F
謝謝!用這個方法OK耶,但很想知道跟position有什麼關係?
12/22 15:44, 3F

12/23 01:07, , 4F
這個寫法#A要加上height:auto才對喔
12/23 01:07, 4F
文章代碼(AID): #1BC4eIO2 (Web_Design)
文章代碼(AID): #1BC4eIO2 (Web_Design)