跨浏览器方法将子div适合其父宽度 [英] Cross browser method to fit a child div to its parent's width
问题描述
我正在寻找一个解决方案,以适应一个孩子 div
到它的父母的 width
。
我在这里看到的大多数解决方案都不支持跨浏览器(例如 display:table-cell;
不支持在IE < = 8
)。
$ b
默认值为 width:auto
,对于块级元素(例如 div
),
请参阅: http://jsfiddle.net/U7PhY/2/
只是为了避免从我的回答中清除:只是不要在子 div $上设置
width
c $ c>。
I'm looking for a solution to fit a child div
into it's parent's width
.
Most solutions I've seen here are not cross-browser compatible (eg. display: table-cell;
isn't supported in IE <=8
).
The solution is to simply not declare width: 100%
.
The default is width: auto
, which for block-level elements (such as div
), will take the "full space" available anyway (different to how width: 100%
does it).
See: http://jsfiddle.net/U7PhY/2/
Just in case it's not already clear from my answer: just don't set a width
on the child div
.
这篇关于跨浏览器方法将子div适合其父宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!