Select elements by attribute in CSS

后端 未结 5 1736
情书的邮戳
情书的邮戳 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 07:58

    You can combine multiple selectors and this is so cool knowing that you can select every attribute and attribute based on their value like href based on their values with CSS only..

    Attributes selectors allows you play around some extra with id and class attributes

    Here is an awesome read on Attribute Selectors

    Fiddle

    a[href="http://aamirshahzad.net"][title="Aamir"] {
      color: green;
      text-decoration: none;
    }
    
    a[id*="google"] {
      color: red;
    }
    
    a[class*="stack"] {
      color: yellow;
    }
    Aamir
    
    Google
    stack

    Browser support:
    IE6+, Chrome, Firefox & Safari

    You can check detail here.

提交回复
热议问题