正如您在this picture中看到的,我在橙色div
內部看到一個綠色的div
,沒有上邊框。橙色div
有一個30px
頂部邊距,但它也推動了綠色div
下降。當然,添加頂部邊框可以解決這個問題,但我需要綠色div
頂部無邊框。我能做什麼?CSS:父母沒有邊框時的邊際保留
.body {
\t border: 1px solid black;
\t border-top: none;
\t border-bottom: none;
\t width: 120px;
\t height: 112px;
\t background-color: lightgreen;
}
.body .container {
\t background-color: orange;
\t height: 50px;
\t width: 50%;
\t margin-top: 30px;
}
<div class="header">Top</div>
<div class="body">
\t <div class="container">Box</div>
</div>
<div class="foot">Bottom</div>
感謝
你能詳細說明所需的效果嗎?您是否希望橙色容器中的文本顯示爲距頂部30像素,還是希望橙色容器的頂部顯示爲綠色容器頂部下方30像素? – Mayo 2009-09-08 15:45:36
相關問題:http://stackoverflow.com/questions/315738/unexpected-margin-with-very-simple-html – mercator 2009-09-08 15:59:56
可能更適合http://doctype.com/ – Nobody 2010-08-03 10:40:18