Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Enthusiast Zone > Art & Graphic Design > CSS Isn't Doing What I Want It To

CSS Isn't Doing What I Want It To
Thread Tools
l008com
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Nov 3, 2010, 02:52 PM
 
I put a lot of thought into the title of this thread...

Anyway, I have a web page, where CSS isn't doing what I want it do. I made a mockup that is the exact same situation, boiled down to just what I'm having trouble with.

The class "group_title" seems to be getting overridden by the "green" class. I thought the "more specific" declarations would override less specific? <li class='group_title'> seems pretty specific to me??

Anyway here's a link to the mock-up page:
CSS Test Page

And for the hell of it, here's the real page (still very much a work in progress so try not to get too off-topic ):
MenuLizard : Boston : The Hen House

And here's the raw code of the mockup if you don't like links:
Code:
<html> <head> <title>CSS Test Page</title> <style> .cell_list { list-style-type: none; margin: 0px; padding-left: 0px; background: #000000; } .green li { border-bottom: #009800 solid 1px; border-left: #009800 solid 1px; border-right: #009800 solid 1px; background: #a1ffa1; } .green li:first-child { border-top: #009800 solid 1px; } .green li:hover { opacity: 0.8; } .group_title { text-align: center; font-weight: bold; /* shouldn't this override the background from "green li"? */ background: #ff0000; } </style> </head> <body> <ul class='cell_list green'> <li class='group_title'>Group 1 <li>Item 1 <li>Item 2 <li>Item 3 <li>Item 4 <li class='group_title'>Group 2 <li>Item 1 <li>Item 2 <li>Item 3 <li>Item 4 <li>Item 5 </ul> </body> </html>
     
andi*pandi
Moderator
Join Date: Jun 2000
Location: inside 128, north of 90
Status: Offline
Reply With Quote
Nov 3, 2010, 03:30 PM
 
Try being more item-specific, like: li.group_title or .green li.group_title . If those don't work, there is always !important which will tell it to override the cascade.
( Last edited by andi*pandi; Nov 4, 2010 at 07:42 AM. Reason: pesky space!)
     
Oisín
Moderator Emeritus
Join Date: Mar 2004
Location: Copenhagen
Status: Offline
Reply With Quote
Nov 3, 2010, 04:19 PM
 
More specific CSS rules will overrule less specific ones—you’ve got both .green li and .group_title specified, and the former is more specific than the latter (it specifies two levels in the CSS hierarchy, whereas .group_title specifies only one). Therefore, the background in .group_title won’t override .green li.

You can just do !important after the declaration you need to override it’s ‘parent’ declaration, or add an extra cascading level to make it even more specific and thus override as it’s supposed to, by doing .green li.group_title.

Edit: Err, started typing this about an hour ago and got distracted, didn’t see Andi’s reply in the meantime.
( Last edited by Oisín; Nov 4, 2010 at 04:43 AM. )
     
andi*pandi
Moderator
Join Date: Jun 2000
Location: inside 128, north of 90
Status: Offline
Reply With Quote
Nov 3, 2010, 04:50 PM
 
I'm relieved to know that your answer concurs with mine.
     
exca1ibur
Mac Elite
Join Date: Oct 2000
Location: Oakland, CA
Status: Offline
Reply With Quote
Nov 3, 2010, 10:25 PM
 
It should to be li.green_title. (no space)
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Nov 3, 2010, 11:22 PM
 
Can I 'bless' a whole class with important, so when applied, it will override everything else? I'm trying to avoid declaring the class of every single item individually. Some of these pages are quite long, and I'm savings many a byte by not having every <li> have it's own class='classname'
     
exca1ibur
Mac Elite
Join Date: Oct 2000
Location: Oakland, CA
Status: Offline
Reply With Quote
Nov 3, 2010, 11:27 PM
 
Just change .green_title to li.green_title and style like you are now.
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Nov 3, 2010, 11:34 PM
 
Ok. I don't really get why that works... but it does and thats good enough for now....
     
exca1ibur
Mac Elite
Join Date: Oct 2000
Location: Oakland, CA
Status: Offline
Reply With Quote
Nov 4, 2010, 12:41 AM
 
It works because you are calling the li node with the class name green_title. If you do it with the space it looks for li and the class within the node, not the class name of the node itself.
     
Oisín
Moderator Emeritus
Join Date: Mar 2004
Location: Copenhagen
Status: Offline
Reply With Quote
Nov 4, 2010, 04:43 AM
 
Originally Posted by exca1ibur View Post
It should to be li.green_title. (no space)
You’re absolutely right; typo fixed.
     
andi*pandi
Moderator
Join Date: Jun 2000
Location: inside 128, north of 90
Status: Offline
Reply With Quote
Nov 4, 2010, 07:41 AM
 
d'oh!
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 10:33 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,