3

How to select those tag with css ? Like this :

<style type="text/css">
[attribute*="test"] {
        background-color: red;
    }
</style>

but it's not work for tag

<test-1>
</test-1>
<test-2>
</test-2>
<test-3>
</test-3>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415
nixon lim
  • 31
  • 3
  • 1
    Interesting question. You may need js for this. https://jsfiddle.net/3wnjvt0k/1/ (just a demo, probably much better ways to do this.) – sol Dec 14 '18 at 07:04
  • so just as a question - `test-1` etc. are custom added DOM element via something or another and you're trying to style them? – treyBake Dec 14 '18 at 08:38

2 Answers2

0

You cannot select elements using the attribute selector, because, well it's for attributes. As far as I know you cannot use wildcards to select elements. You will need e.g. Javascript to select your elements and add classes or attributes which you can then target using CSS. In any case I would try to avoid these kind of wild card selectors for performance reasons.

See also: CSS Wildcard element name selection

Djdev
  • 23
  • 5
-2

pls try this code:

<test-1 class="ts">1
</test-1>
<test-2 class="ts">2
</test-2>
<test-3 class="ts">3
</test-3>
<style> 
[class*="ts"] {
  background: #ffff00;
}
</style>
AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57