?
Solved

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

Posted on 2009-05-13
8
Medium Priority
?
577 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 1000 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
Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

 
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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

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…
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 learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

719 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