Select elements by attribute in CSS

后端 未结 5 1819
情书的邮戳
情书的邮戳 2020-11-22 07:49

Is it possible to select elements in CSS by their HTML5 data attributes (for example, data-role)?

5条回答
  •  星月不相逢
    2020-11-22 08:19

    It's worth noting CSS3 substring attribute selectors

    [attribute^=value] { /* starts with selector */
    /* Styles */
    }
    
    [attribute$=value] { /* ends with selector */
    /* Styles */
    }
    
    [attribute*=value] { /* contains selector */
    /* Styles */
    }
    

提交回复
热议问题