Cross browser method to fit a child div to its parent's width

前端 未结 6 1010
礼貌的吻别
礼貌的吻别 2020-12-04 15:01

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 com

6条回答
  •  情书的邮戳
    2020-12-04 15:38

    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.

    You might instead be interested in box-sizing: border-box.

提交回复
热议问题