if a div is 100% width by default

后端 未结 3 1281
日久生厌
日久生厌 2021-01-02 06:32

If a div is 100% width, should I still put in width: 100%;? I look at a lot of code and it\'s always in there even though by default a div

3条回答
  •  滥情空心
    2021-01-02 06:45

    No, doing so can actually cause problems. 100% is not the same as auto. width refers to the width of the content, excluding borders, padding and margins. auto automatically computes the width such that the total width of the div fits the parent, but setting 100% will force the content alone to 100%, meaning the padding etc. will stick out of the div, making it larger than the parent.

    See this for an example

提交回复
热议问题