Solved

What CSS to use for nested ID Selectors on two different pages?

Posted on 2009-05-13
8
572 Views
Last Modified: 2012-05-06
I'm working with the Able Commerce shopping cart. Two different pages both contain the same product list section as shown below. I want two different styles for the ProductList divs on each page. For example, I want #HomePage + #ProductList to be a yellow background while #CategoryPage + #ProductList to be a red background.

I tried using #HomePage + #ProductList and #HomePage > #ProductList styles but that didn't work. Is this possible?

<!-- Home Page -->
<div id="HomePage">
  <div id="ProductList">
  </div>
</div>
 
<!-- Category Page -->
<div id="CategoryPage">
  <div id="ProductList">
  </div>
</div>

Open in new window

0
Comment
Question by:ZekeLA
[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
  • 4
  • 3
8 Comments
 
LVL 12

Accepted Solution

by:
alien109 earned 250 total points
ID: 24379949
To select them independently of each other you should be able to use the following selectors

#HomePage #ProductList {
    <!-- style attributes -->
}

#CategoryPage #ProductList {
    <!-- style attributes -->
}
0
 
LVL 20

Expert Comment

by:ddayx10
ID: 24379982
If I understand what you want the CSS would be:

#HomePage #ProductList{background:#CCCCCC;}
#CategoryPage  #ProductList{background:#FFFCCC;}

Just an example.

dday
0
 
LVL 1

Author Comment

by:ZekeLA
ID: 24380010
Are you sure or have a working example to demonstrate? I tried that and it doesn't work. The joint id selectors don't apply.
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 12

Expert Comment

by:alien109
ID: 24380013
ZekeLA,

You may find this useful in the future on selectors and browser support
http://www.quirksmode.org/css/contents.html
0
 
LVL 1

Author Comment

by:ZekeLA
ID: 24380032
I should clarify my html. The nesting is actually several levels. For example, I really have:

<div id="HomePage">
 <div id="abc">
   <div id="def"
      etc.
     <div id="ProductList"
0
 
LVL 12

Expert Comment

by:alien109
ID: 24380050
As long as ProductList is an ancestor of HomePage and CategoryPage, it should work.

Try the attached code. Works fine for me in FF3, IE7, and IE6. FYI - Never use duplicate ID's, I only did for the purpose of the example. :)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta http-equiv="Content-Language" content="en-us" />
 
<style type="text/css">
 
#HomePage #ProductList {
    background-color:#f00;
}
 
#CategoryPage #ProductList {
    background-color:#00f;
}
 
</style>
 
</head>
<body>
 
<!-- Home Page -->
<div id="HomePage">
	<div id="ProductList">CONTENT</div>
</div>
 
<!-- Category Page -->
<div id="CategoryPage">
	<div id="ProductList">CONTENT</div>
</div>
 
 
</body>
 
</html>

Open in new window

0
 
LVL 1

Author Comment

by:ZekeLA
ID: 24380136
I was mistaken about the element ids so my problem is actually with the underlying code, not the css. I tested your solutions and it definitely works. My bad. By the way, my issue is with two different pages, not the same page so I wouldn't be using duplicate ids. Thanks.
0
 
LVL 12

Expert Comment

by:alien109
ID: 24380251
Glad you got things sorted. And I assumed you didn't have duplicate IDs, just wanted to clarify that I was only doing it for purposes of demonstration.

Cheers.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

738 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