user1486133 user1486133 - 11 months ago 33
CSS Question

Use a wildcard in CSS selector to style when value is present

I am trying to style an element only when that element has a value attribute.

The value attribute is variable (it's a date), but it's the only thing that changes between "no value" and "has value" which I need to style differently.

Is it possible to use a wildcard in the CSS selector ascertain whether the value attribute is present? E.g:


<input class="thing" value="variable-something">...</input>
<input class="thing">...</input>


.thing[value="*"] {
.thing[value=*] {

I've tried this solution but use of the
makes it look for a specific string. Doing
is invalid and won't compile.

Any advice?

Answer Source
<input type="text" value="">
<input type="text">

  background: #ccc;

Try it yourself