• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

Universal CSS Question

Hi -

I've got a group of div IDs that conform to a specific naming convention.  Like, for instance, there's...

id="hello-1"
id="hello-2"
id="hello-3"
etc etc.

How do I declare a style so that anything beginning with "hello-" receives a certain style?  I was reading about asterisks - like "hello-* { }" - but that doesn't seem to be working.

"?"
0
erzoolander
Asked:
erzoolander
  • 8
  • 5
  • 3
  • +1
1 Solution
 
LZ1Commented:
Why couldn't you use multiple classes instead? The only difference is CSS elements can't start with a number.
<div class="hello one">Styled </div>
<div class="hello two">Styled </div>
<div class="hello three">Styled </div>

Open in new window

0
 
erzoolanderAuthor Commented:
Because the HTML is being generated by our CMS system - and the CMS system is outputting the HTML in this type of form...

<div id="hello-1">Text</div>
<div id="hello-2">Text</div>
and so on - potentially ad-infinitum.

I figured it'd be easier to just come up with a general CSS rule that applied to anything that began with "hello-*" than it would be to re-write the CMS system
0
 
LZ1Commented:
I see.  The asterisk doesn't work like that unfortunately. So you have no way to control the output of the CMS?  
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
erzoolanderAuthor Commented:
If need be, yeah.  Was kinda hoping there was a quicker CSS rule I could take advantage of though.  Altering the output of the CMS was my second choice.
0
 
Dave BaldwinFixer of ProblemsCommented:
If the CSS is the same, you can put multiple id's on the same line.
#hello-1, #hello-2, #hello-3 {
color: black;
}

Open in new window

0
 
erzoolanderAuthor Commented:
The problem is that the "1",  "2", "3", etc are variable...and unpredictable.  Therefore I won't know ahead of time what they will be.  I just used that as an illustrative example.

It's more fair to say...

"hello-x" - with x being an indeterminate.  It may be anything. That's why I was hoping for a wildcard option.

I guess there is none?
0
 
LZ1Commented:
I wonder if we may be able to do something like that with jquery.  Can you use Javascript/Jquery?
0
 
erzoolanderAuthor Commented:
Actually I found something when I was searching around in a random place.  This appears to work - although I haven't tested it in IE yet.

div[id*="hello-"] {
    color:red;
}
0
 
LZ1Commented:
And it's valid too! I didn't think that would work honestly, especially in IE.  Let us know.
0
 
erzoolanderAuthor Commented:
Yep!  Works in IE 7, 8 and 9.

Woohoo!
0
 
LZ1Commented:
Awesome!  Well, I learned something today too!
0
 
erzoolanderAuthor Commented:
:)

Thanks for the help!
0
 
erzoolanderAuthor Commented:
Ended up finding the solution some other obscure place - but glad to add it to the knowledge base.

I suppose the appropriate title/tag should have been CSS Wildcard.
0
 
Dave BaldwinFixer of ProblemsCommented:
We would like to know where you found that.
0
 
Dave BaldwinFixer of ProblemsCommented:
Cool, thanks.
0
 
Prafulla MaharjanCommented:
You create in css as

.hello_1{}
.hello_2{}
.hello_3{}

this is class, You can call any number of times.
 but  when u create
#hello_1{}

this is Id, you can call only one time , so that it will be a problem

After creating the  class

just you call in Div


<div class="hello_1"></div>


Please try this
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 8
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now