if a div is 100% width by default

后端 未结 3 1254
日久生厌
日久生厌 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:37

    I'm not sure if the children elements will adapt themselfs with procentual values if their parent doesn't have a width attribute. Otherwise it's just semantic and good practice to put width: 100%; if the div is supposed to span 100% of it's parent container.

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-01-02 06:50

    nope, pretty useless I think to give it a 100% width unless you have a background-color or image or something in this div.

    0 讨论(0)
提交回复
热议问题