Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS selector for numbered class/id

I have the following situation:

<div id="myMenu">
   <div id="menu0">stuffs</div>
   <div id="menu1">stuffs</div>
   <div id="menu2">stuffs</div>
   ...... and so on
</div>

My requirement is to access all div having id $=menu inside myMenu except menu0, as my menu can have like 10 to 15 item so one way is to do:

 #myMenu > menu1 {style}
 #myMenu > menu2 {style}
 so on... 15 times

but as I have to give same style to all of them , it seems unnecessary , I am looking for CSS selector which will fit correctly for my requirement also having compatible to IE8.

Any help is greatly appreciated.

like image 987
Vivek Avatar asked Dec 08 '22 05:12

Vivek


1 Answers

If you always have the #menu0 element, you can use the general sibling selector that is IE8 compliant:

    #menu0 ~ [id^="menu"] {
        color: red;
    }
<div id="myMenu">
   <div id="menu0">stuffs</div>
   <div id="menu1">stuffs</div>
   <div id="menu2">stuffs</div>
</div>

or use classes (along with ids) that would fit better.

like image 119
Andrea Ligios Avatar answered Dec 28 '22 22:12

Andrea Ligios