2 replies [Last post]
roytheboy
roytheboy's picture
Offline
Guru
North Wales, UK
Last seen: 9 years 18 weeks ago
North Wales, UK
Timezone: GMT+1
Joined: 2004-09-18
Posts: 2233
Points: 41

Does anyone happen to know if the following example selector can be written in a shorter style without losing any functionality?

#page .inset1 h2, #page .inset2 h2, #page .inset3 h2, #page .inset4 h2, #page .inset5 h2, #page .inset6 h2, #page .inset7 h2, #page .inset8 h2 {  
	margin: 0;  
	padding: 5px 10px 5px 10px;  
}  

Before you ask; it is part of a CMS whereby the user can choose to style a text-containing <div> as an inset box in one of eight different visual styles. In this example I want to set the h2 padding globally to all eight versions. What a shame CSS won't accept regular expressions!

Life's a b*tch and then you die!

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 1 week 5 days ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5344
Points: 2965

css shorthand

Hi roytheboy,
Without seeing the page source we can only guess.
So here are three guesses you may already have tried

h2 {  
   margin: 0;  
   padding: 5px 10px 5px 10px;  
}  
#page h2 {  
   margin: 0;  
   padding: 5px 10px 5px 10px;  
}  
#page div h2 {  
   margin: 0;  
   padding: 5px 10px 5px 10px;  
}  

Hope that helps

roytheboy
roytheboy's picture
Offline
Guru
North Wales, UK
Last seen: 9 years 18 weeks ago
North Wales, UK
Timezone: GMT+1
Joined: 2004-09-18
Posts: 2233
Points: 41

css shorthand

Thanks for trying Tony. I can't give a link at the moment as the project is CIC until it goes live. I think the answer is going to be that there is no way of shortening the grouping syntax of the selectors. I just thought that if anyone would know how, the regulars on this forum would. It's not important - just a question of code neatness.

Unfortunately, I cannot use your suggestions as there are other h2 tags within div's within #page that must not be affected by this property. The question concerned the issue of syntax rather than page structure.

Thanks again Smile

Life's a b*tch and then you die!