Is it possible to select elements in CSS by their HTML5 data attributes (for example, data-role
)?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
- Adding a timeout to a render function in ReactJS
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
andclass
attributesHere is an awesome read on Attribute Selectors
Fiddle
Browser support:
IE6+, Chrome, Firefox & Safari
You can check detail here.
If you mean using an attribute selector, sure, why not:
There are a variety of attribute selectors you can use for various scenarios which are all covered in the document I link to. Note that, despite custom data attributes being a "new HTML5 feature",
browsers typically don't have any problems supporting non-standard attributes, so you should be able to filter them with attribute selectors; and
you don't have to worry about CSS validation either, as CSS doesn't care about non-namespaced attribute names as long as they don't break the selector syntax.
It's also possible to select attributes regardless of their content, in modern browsers
with:
For example: http://codepen.io/jasonm23/pen/fADnu
Works on a very significant percentage of browsers.
Note this can also be used in a JQuery selector, or using
document.querySelector
It's worth noting CSS3 substring attribute selectors