Setting width:auto leads to width:100%

后端 未结 3 1862
情深已故
情深已故 2021-01-02 04:24

I am a little bit tired right now (out of coffee), so I am unable to figure this out.

When I set p.style.width = auto (the blue one), why is its w

3条回答
  •  礼貌的吻别
    2021-01-02 04:54

    It's all explained in the spec

    http://www.w3.org/TR/CSS2/visudet.html#blockwidth

    O.O

    Essentially, auto means taking all the other specified paddings, borders and margins into account, fill the remaining space (assuming only the width is set to auto). So effectively 100% minus borders, padding and margins.

    To fix, just set it to match the other elements, or stick them all in a containing element with a set width.

提交回复
热议问题