我阅读了“ [PRO HTML和CSS设计模式]”,了解了如何进行此类操作。该display:block
是为默认显示的值div
,但我喜欢,使其明确。容器必须是正确的类型;position
属性是fixed
,relative
,或absolute
。
.stretchedToMargin {
display: block;
position:absolute;
height:auto;
bottom:0;
top:0;
left:0;
right:0;
margin-top:20px;
margin-bottom:20px;
margin-right:80px;
margin-left:80px;
background-color: green;
}
<div class="stretchedToMargin">
Hello, world
</div>