Do values in CSS attribute selector values need to be quoted?

前端 未结 4 1560
感情败类
感情败类 2020-12-18 05:55

e.g.:

a[href=\"val\"]

Does \"val\" need to have quotes around it? Single or double are acceptable? What about for integers?

4条回答
  •  青春惊慌失措
    2020-12-18 06:29

    According to the examples in the CSS 2.1 specs, quotes are optional.

    In the following example, the selector matches all SPAN elements whose "class" attribute has exactly the value "example":

    span[class=example] { color: blue; }
    

    Here, the selector matches all SPAN elements whose "hello" attribute has exactly the value "Cleveland" and whose "goodbye" attribute has exactly the value "Columbus":

    span[hello="Cleveland"][goodbye="Columbus"] { color: blue; }
    

    Numbers are treated like strings, i.e. they can be quoted, but they don't have to.

提交回复
热议问题