div+css盒模型

1 篇文章 0 订阅
1 篇文章 0 订阅

盒模型可以说是div+css中的精髓了

我们平时设置的div{width:200px;height:200px} 属性时,设置的都是content的宽和高,当你做站时开始确定好了宽高,写了进去。

后期增大margin或padding的时候,你的宽高就会增大,这样可能挤破盒子,把别的地方内容挤走。

这里有另一种思想,即盒嵌套模型。外部一个div设置宽高,内部一个div写内容,内部div不用写宽高,因为是块级元素,他会自动填充满这个父盒子。然后设置宽高的时候仅需在内部盒中设置即可,这样你可以随便更改了。

<div id="outer_box">
	<div id="inner_box">
        <h4>An h4 heading</h4>
        <p>The heading and this paragraph sit in a column with a width of 170px. Because they are block level elements, their boxes expand horizontally to fill their containing element. Adding 10 pixels of padding to the container makes the container wider by 20px.</p>
	</div>
</div>

div#outer_box {width:170px; background:#FCC;}
div#inner_box {padding:10px;}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值