css - 100%+ padding? [英] css - 100% + padding?

查看:114
本文介绍了css - 100%+ padding?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数人都知道,

一个100%的div与5px填充实际上是100%+ 10px宽。

a 100% div with a 5px padding is actually 100% + 10px wide.

一个显而易见的解决方案是将子div包装在具有10px边距的包装器中
方法需要您添加额外的标记,我正在寻找一个方法做100%+填充没有额外的div。

One obvious solution to this is to wrap the child div in a wrapper that has a 10px margin however this method requires you to add extra markup, I am looking for a way to do 100%+padding without the extra div.

任何想法?

推荐答案

阻止像< div> 的元素在填充后自动假定宽度为100% 。也就是说你应该能够通过指定一个填充,保留宽度在 auto 并确保元素 display:block code>(< div> 的默认值)。

Block elements like <div>s automatically assume a 100% width after padding. I.e. you should be able to achieve the desired effect simply by specifying a padding, leaving the width on auto and making sure the element has display: block (default for <div>).

http://jsfiddle.net/EMYBm/8/

这篇关于css - 100%+ padding?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆