跨浏览器方法将子div适合其父宽度 [英] Cross browser method to fit a child div to its parent's width

查看:75
本文介绍了跨浏览器方法将子div适合其父宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个解决方案,以适应一个孩子 div 到它的父母的 width



我在这里看到的大多数解决方案都不支持跨浏览器(例如 display:table-cell; 不支持在IE < = 8 )。



$ p






$ 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屋!

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