Forum Moderators: not2easy

Message Too Old, No Replies

Attribute selectors matching numeric values

Matching select elements with size > 1

         

Fotiman

3:20 pm on Feb 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Given the following markup:


<select size="3" name="foo" multiple="multiple">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select size="1" name="bar" multiple="multiple">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>


Is there a way to target only the select element that has a size value greater than 1? Something along the lines of:

select[size>1] {}

(but I know the > is invalid here). Is this not possible?

alt131

9:32 pm on Feb 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The negation pseudo class might be an option - although it takes a sort of "less than" approach rather than the "greater than" approach you were asking about:
select:not([attribute="1"]) {background-color:red}

The bad news (am sure you are aware) is the status of :not (and therefore limited implementation), compounded by limited implementation of attribute selectors generally (going back a few versions), and the variations of property/value combinations that have been implemented on form elements.

Depending on the versions you need to support, something (unpleasant) like
select[attribute] {background-color:red;}
select[attribute="1"] {background-color:transparent;}
or
select {background-color:red;}
select[attribute="1"] {background-color:transparent;}
... will be implemented by more versions

Where the word attribute needs to be replaced with the word size - the board is treating the example selector as a forum style code, complaining the style code hasn't been closed - and refusing to post ;)

Fotiman

1:02 am on Feb 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks. Unfortunately, it seems like this was an oversight when they defined the CSS specs. :) Oh well.