Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS style #elements[1-10]

Tags:

arrays

css

If I had 5 divs with ids "element1", "element2", etc..., is there a way to style an array of elements with something like:

#elements[1-10]{
 position:relative;
}

I know you guys probably think I'm nuts, but I'm dealing with some code that is auto generated and I would have to edit the core files of this cms which I don't want to do in case client upgrades in future.

With that said, it is out of the question for me to change the IDs manually to a class.

like image 890
Senica Gonzalez Avatar asked Sep 01 '26 13:09

Senica Gonzalez


2 Answers

This works in many modern browsers... except IE:

<style type="text/css">
  p[id*=elements] {
    color: #F00;
  }
</style>

HTML

<p id="elements1">Elements 1</p>
<p id="elements2">Elements 2</p>
<p id="elements3">Elements 3</p>
<p id="elements4">Elements 4</p>
<p id="elements5">Elements 5</p>

But there's - of what I know - no way of limiting it.

like image 89
Gert Grenander Avatar answered Sep 04 '26 04:09

Gert Grenander


I think there's no arrays in CSS. Have you tried considering jQuery?

like image 32
hallie Avatar answered Sep 04 '26 02:09

hallie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!