我今天在玩jQuery幻燈片。當我注意到奇怪的事情時,我設法創建了它。其中放置幻燈片放映的div #feature
似乎以某種方式粘貼到其母元素#content
。當我將margin: 10px auto
添加到#feature
div時,#content
div也相對於其父元素降低了10px。爲什麼CSS中的邊距不一致?奇怪的行爲
誰能告訴我我在這裏做錯了什麼?
爲您提供完整的代碼將創建一個爛攤子,但這裏有一個鏈接:
CSS的#feature
:
#feature {
width:940px;
margin: 10px auto;
position: relative;
height:500px;
overflow: hidden;
clear: both;
box-shadow: 0px 0px 5px 2px #000;
}
和CSS #content
:
#content{
min-height:800px;
background-color: #fff;
}
我的朋友noti吸引了一件有趣的事情。如果您將margin-bottom: 30px
添加到#menu
內容中的空白10px空間被正確填充,但邊距問題仍未解決。
你的答案似乎在訣竅:)謝謝。你能解釋一下嗎?它是如何工作的,爲什麼'overflow:auto'修復它? – Dharman
正如我可以理解的溢出:自動告訴#內容計數內部div的所有邊距作爲#內容div內的空間。 –