Looking for a css selector for custom elements.
<myApp-thing1></myApp-thing1>
<myApp-thing2></myApp-thing2>
<myApp-thing3></myApp-thing3>
I want to apply a css class to any element that starts with <myApp-...>
. Is this possible?
No, there's not. Only the attribute selector can do this. The name of the attribute doesn't matter.
[class^="value"]
This hits:
<div class="value-a"></div>
<div class="value-b"></div>
<div class="value-c"></div>
https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors
What you're suggesting isn't possible, however, what IS possible is this:
<div myApp="thing1">
Then in CSS you can do this:
div[myApp] {
background-color:pink;
}
You can even target a specific <div>
with the myApp
attribute by doing this in CSS:
div[myApp="thing1"] {
background-color:red;
}
Hope this helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.