|
|
CSS Isn't Doing What I Want It To
|
|
|
|
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status:
Offline
|
|
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>
|
|
|
|
|
|
|
|
|
Moderator
Join Date: Jun 2000
Location: inside 128, north of 90
Status:
Offline
|
|
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!)
|
|
|
|
|
|
|
|
|
Moderator Emeritus
Join Date: Mar 2004
Location: Copenhagen
Status:
Offline
|
|
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.
)
|
|
|
|
|
|
|
|
|
Moderator
Join Date: Jun 2000
Location: inside 128, north of 90
Status:
Offline
|
|
I'm relieved to know that your answer concurs with mine.
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Oct 2000
Location: Oakland, CA
Status:
Offline
|
|
It should to be li.green_title. (no space)
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status:
Offline
|
|
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'
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Oct 2000
Location: Oakland, CA
Status:
Offline
|
|
Just change .green_title to li.green_title and style like you are now.
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status:
Offline
|
|
Ok. I don't really get why that works... but it does and thats good enough for now....
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Oct 2000
Location: Oakland, CA
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Moderator Emeritus
Join Date: Mar 2004
Location: Copenhagen
Status:
Offline
|
|
Originally Posted by exca1ibur
It should to be li.green_title. (no space)
You’re absolutely right; typo fixed.
|
|
|
|
|
|
|
|
|
Moderator
Join Date: Jun 2000
Location: inside 128, north of 90
Status:
Offline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|