下面是解決方案。
CSS:
<style>
#parentBox {
border: 2px solid red;
height: 180px;
width: auto;
}
#childBox {
background: -moz-linear-gradient(top, rgba(255,255,255,0) 0%, rgba(255,255,255,0) 13%, rgba(242,242,242,1) 14%, rgba(242,242,242,1) 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(top, rgba(255,255,255,0) 0%,rgba(255,255,255,0) 13%,rgba(242,242,242,1) 14%,rgba(242,242,242,1) 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, rgba(255,255,255,0) 0%,rgba(255,255,255,0) 13%,rgba(242,242,242,1) 14%,rgba(242,242,242,1) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00ffffff', endColorstr='#f2f2f2',GradientType=0); /* IE6-9 */
height: 70%;
margin: 20px 70px 20px 340px;
}
</style>
HTML:
<div id="parentBox">
<div id="childBox">advertisement</div>
</div>
Margin屬性是用來給從父元素從它裏面的文本元素餘地,不。如果你想這樣做,你必須使用填充,但你不能將文本移動到div的邊界之上,那麼你正在div中寫入文本。爲此,您應該在div上方寫入文本,而不是在div內。 –