style width vs width attribute in HTML

前端 未结 3 916
渐次进展
渐次进展 2021-01-12 16:16

I saw last post similar to my question HTML5 canvas style height vs attribute height
But in that post, there was no clear information regarding which one will work and

3条回答
  •  半阙折子戏
    2021-01-12 17:04

    The width attribute is invalid in a select element. What matters more, this restriction is imposed by browsers: they ignore the attribute. (Long time ago, Netscape 4 supported it, and it was described in the HTML 3.0 draft, which expired in 1995. Some legacy code, maybe even legacy coding practices, may still reflect such things!)

    So answer is simple: they differ so that the width attribute in HTML has no effect (so the element takes its default width), whereas the width property in CSS works in the normal CSS way.

    The width attribute is not a general attribute in HTML: it is allowed for a certain set of elements and defined individually for them.

提交回复
热议问题