Solved

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

Posted on 2009-05-13
8
573 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
Myth Busting: MongoDB Scalability (it scales!)

I was talking with one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. He mentioned to me that several customers have been telling him that “MongoDB doesn’t scale!” MongoDB’s scalability was in question?

My response was, “Is that a joke?"

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
This video teaches users how to migrate an existing Wordpress website to a new domain.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

623 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