Solved

Universal CSS Question

Posted on 2011-09-09
17
215 Views
Last Modified: 2012-08-14
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
Comment
Question by:erzoolander
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 3
  • +1
17 Comments
 
LVL 30

Expert Comment

by:LZ1
ID: 36513346
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
 
LVL 2

Author Comment

by:erzoolander
ID: 36513579
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
 
LVL 30

Expert Comment

by:LZ1
ID: 36513823
I see.  The asterisk doesn't work like that unfortunately. So you have no way to control the output of the CMS?  
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:erzoolander
ID: 36514025
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
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 36514125
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
 
LVL 2

Author Comment

by:erzoolander
ID: 36514537
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
 
LVL 30

Expert Comment

by:LZ1
ID: 36514569
I wonder if we may be able to do something like that with jquery.  Can you use Javascript/Jquery?
0
 
LVL 2

Accepted Solution

by:
erzoolander earned 0 total points
ID: 36514600
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
 
LVL 30

Expert Comment

by:LZ1
ID: 36514609
And it's valid too! I didn't think that would work honestly, especially in IE.  Let us know.
0
 
LVL 2

Author Comment

by:erzoolander
ID: 36514627
Yep!  Works in IE 7, 8 and 9.

Woohoo!
0
 
LVL 30

Expert Comment

by:LZ1
ID: 36514633
Awesome!  Well, I learned something today too!
0
 
LVL 2

Author Comment

by:erzoolander
ID: 36514640
:)

Thanks for the help!
0
 
LVL 2

Author Closing Comment

by:erzoolander
ID: 36534808
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
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 36514679
We would like to know where you found that.
0
 
LVL 2

Author Comment

by:erzoolander
ID: 36514981
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 36515081
Cool, thanks.
0
 
LVL 3

Expert Comment

by:Prafulla Maharjan
ID: 36515485
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question