input[type='text'] CSS selector does not apply to default-type text inputs?

后端 未结 5 1245
醉梦人生
醉梦人生 2021-02-02 05:26

The default input type is \'text\'. I have always assumed then that CSS declarations targeting input[type=\'text\'] would affect those inputs even if the type was n

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-02 05:29

    The CSS uses only the data in the DOM tree, which has little to do with how the renderer decides what to do with elements with missing attributes.

    So either let the CSS reflect the HTML

    input:not([type]), input[type="text"]
    {
    background:red;
    }
    

    or make the HTML explicit.

     /* Is Not Red */
    

    If it didn't do that, you'd never be able to distinguish between

    element { ...properties... }
    

    and

    element[attr] { ...properties... }
    

    because all attributes would always be defined on all elements. (For example, table always has a border attribute, with 0 for a default.)

提交回复
热议问题