Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS attribute selector, multiple classes, wildcards applied to one class definition possible?

Consider the following markup with 2 possibilities:

<input class="someclass ng-valid ng-invalid-otherstuff ng-valid-amountdetermined   some-other-class">
<input class="someclass ng-invalid ng-valid-otherstuff ng-invalid-amountdetermined some-other-class">

"Amount" is a variable word, this could be anything, "message", "account", anything really. I need to be able to make the distinction in CSS. The attribute selector fails short as it considers the entire attribute value for ^, *, | or even ~.

I would need to single out a class, then check if that class is "ng-valid-*determined". It appears to me this is simply not possible using css, or am I missing something?

A workaround would be to generate "ng-valid-determined*" but this is exactly what I would like to avoid. Does anyone have any ideas on this? As a clarification, I do not know what the ''someclasses' are, I cannot use them for pinpointing my css selector. The problem is exactly that the class I need could be located anywhere inside the class array.

I created a fiddle to visualise the problem, this is of course not the solution as I need to be able to target ng-valid-*determined or ng-invalid-*determined

http://jsfiddle.net/mC2EW/

Not to be confused with using two css attribute selectors with *

//edit1: simplified the question //edit2: added a fiddle

like image 881
smets.kevin Avatar asked Feb 15 '13 15:02

smets.kevin


1 Answers

Even though this is an old one, I was looking for a similar solution. I believe I have the best answer, please see my pen.

HTML

<input class="someclass ng-valid ng-invalid-otherstuff
ng-valid-amountdetermined some-other-class"> <input class="someclass
ng-invalid ng-valid-otherstuff ng-invalid-amountdetermined
some-other-class">

CSS

[class*=ng-valid][class*=ng-invalid-otherstuff][class*=determined] {
background: #000; }
[class*=ng-invalid][class*=ng-valid-otherstuff][class*=determined] {
background: #ddd; }

It turns out that while you cannot target multiple wildcards within the same attribute selector, you can chain wildcard attribute selectors to find your target.

like image 134
Morgan Feeney Avatar answered Oct 26 '22 05:10

Morgan Feeney