473,808 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Descendant selector for nested classes

I'm trying to localize the setting of colors on a series of webpages
by defining color palettes that will be used for various page areas.

I've defined some palette classes like .clrLt, .clrMd, .clrDk and
associated link colors using selectors. One of the aims is to ensure
that matching text color, background, and link colors are maintained.

These palettes are applied as multiple classes to various page modules
which also have abstract classes that define other characteristic.
Modules may contain other modules.

The problem that I run into is that my link colors are not changing
based on their immediate container's class. If a link is inside a
..clrLt container, which is itself inside a .clrMd container, the link
colors are defined by the .clrMd selector. It appears that the
browsers don't consider an immediate dependacy to be a significant as
which class was defined last. If I could use a child selector ">" I
might be able to override this, at least for links directly in the
parent container. The same thing happens with other nesting and color
combinations. If I reorder the class definition, I get different
results, but they always favor the last define class.

I thought about defining special case nesting selectors like ".clrDk
..clrLT a:link" but there is no systematic way to predict that and the
combinations get out of hand very quickly.

Any ideas?
= simplified css example =
..clrLt{
background-color: #FFFFFF;
color: black;
}
..clrLt a:link,.clrLt a:visited, .clrLt a:active, .clrLt a:hover{
color: red;
}

..clrMd{
background-color: #666666;
color: #CCFFFF;
}
..clrMd a:link, .clrMd a:visited, .clrMd a:active, .clrMd a:hover{
color: yellow;
}

..clrDk{
background-color: #000000;
color: #FFFFFF;
}
..clrDk a:link, .clrDk a:visited, .clrDk a:active, .clrDk a:hover{
color: Aqua;
}

= simplified html example =

<body class="clrLt">b ody content with light background

<div class="nav clrDk">
<a href="#">link</a>
<a href="#">link</a>
<a href="#">link</a>
</div>

<div class="content clrMd">
some content with medium background "><a href="#">link</a>

<div class="inset clrLt">some inset content with light background <a
href="#">link</a>
</div>

</div>

</body>
Jul 20 '05 #1
2 3864
te***********@g mail.com (tagbert) wrote:
I'm trying to localize the setting of colors on a series of webpages
by defining color palettes that will be used for various page areas.

I've defined some palette classes like .clrLt, .clrMd, .clrDk and
associated link colors using selectors.
In general this is not considered best practice. Think about defining
your class names based on what the element is (.navigation, .footnote,
etc) rather than on its presentation (which may vary as the site is
restyled).
One of the aims is to ensure
that matching text color, background, and link colors are maintained.
Then why, in the styles you posted, do you not specify a
background-color everytime you specify a color?
The problem that I run into is that my link colors are not changing
based on their immediate container's class. If a link is inside a
.clrLt container, which is itself inside a .clrMd container, the link
colors are defined by the .clrMd selector. It appears that the
browsers don't consider an immediate dependacy to be a significant as
which class was defined last.
This is correct behaviour as per the CSS spec.
Descendent selectors apply to all descendents, no matter how many
generations removed. So your selectors are all equally specific and
hence the last specified in the stylesheet takes precedence.
I thought about defining special case nesting selectors like ".clrDk
.clrLT a:link" but there is no systematic way to predict that and the
combinations get out of hand very quickly.


Without seeing your pages it's hard to make recommendations but I
would suggest being a bit stricter and placing limits on which
combinations are permitted. It doesn't do your users any favours to
have multiple link colours scattered at random throughout your pages.
Especially as your already harming usability by using the same colour
for unvisited and visited links.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net > <http://steve.pugh.net/>
Jul 20 '05 #2
Steve Pugh <st***@pugh.net > wrote in message news:<02******* *************** **********@4ax. com>...
te***********@g mail.com (tagbert) wrote:
I'm trying to localize the setting of colors on a series of webpages
by defining color palettes that will be used for various page areas.

I've defined some palette classes like .clrLt, .clrMd, .clrDk and
associated link colors using selectors.


In general this is not considered best practice. Think about defining
your class names based on what the element is (.navigation, .footnote,
etc) rather than on its presentation (which may vary as the site is
restyled).
One of the aims is to ensure
that matching text color, background, and link colors are maintained.


Then why, in the styles you posted, do you not specify a
background-color everytime you specify a color?
The problem that I run into is that my link colors are not changing
based on their immediate container's class. If a link is inside a
.clrLt container, which is itself inside a .clrMd container, the link
colors are defined by the .clrMd selector. It appears that the
browsers don't consider an immediate dependacy to be a significant as
which class was defined last.


This is correct behaviour as per the CSS spec.
Descendent selectors apply to all descendents, no matter how many
generations removed. So your selectors are all equally specific and
hence the last specified in the stylesheet takes precedence.
I thought about defining special case nesting selectors like ".clrDk
.clrLT a:link" but there is no systematic way to predict that and the
combinations get out of hand very quickly.


Without seeing your pages it's hard to make recommendations but I
would suggest being a bit stricter and placing limits on which
combinations are permitted. It doesn't do your users any favours to
have multiple link colours scattered at random throughout your pages.
Especially as your already harming usability by using the same colour
for unvisited and visited links.

Steve


Sorry, those were 'streamlined' class definitions just as the html
was. I had condensed this down to a minimum for illustrative purposes.
The problem still exists in this version.

The whole point of this is to keep color combinations together. To
make sure that background, text, and link colors are compatible within
a given area of the page. If we change the colors, we will only change
them as a group. If we change which set of colors is used for an area
of the page, then we will either treat it as an exception and use id
to override the class or we may be restructuring that page and will
need to re-evaluate the color usage anyway. I also collapsed the link
styles down into a single definition, though in the real stylesheet,
they are separate.

I see what the browser is doing. I just hadn't expected that behavior.
I had assumed that it did some weighting based on the nesting
structure. I guess not. I'll probably have to define separate link
classes for links on each background color.

Thanks, anyway.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2036
by: Laurence Tureaud | last post by:
hello i'm just getting started with CSS & am reading through Eric Meyer on CSS, specifically the first chapter. he creates these styles: td#advert {stuff} #content-top td { stuff } tr td#sidetop {stuff }
7
2329
by: Philip Herlihy | last post by:
If I'm reading my reference books correctly, I should be able to pick out cells in a table by combining a <col> selector with a class selector, like this: col#thisid td.thisclass {color: red; } ... but it doesn't work. I can get the unadorned <col> selector to work in IE6 and Opera (not Dreamweaver 2004): col#thiscol {color: red; } ... but when I add a descendent selector it stops working. I'd be grateful for advice or comments.
25
11954
by: Tim & Alethea Larson | last post by:
In order to mark links leaving my site, I recently added this rule to my stylesheet. A:after { content: "\2197" } The character is a northeast-pointing arrow, since that seems to be fairly common notation for this. I wanted to avoid using an image, though, and this content rule works great!
5
1976
by: Andrew Poulos | last post by:
If I have an external stylesheet that is @imported into my page and it has an element that looks like this: * html td { font-style: italic; } how can I use javascript to change the font style to 'normal'? Andrew Poulos
3
1297
by: | last post by:
Hi there, I'm relatively new to CSS and having a difficult time with something that should be simple. I've searched this group for answers to this problem, but am afraid I haven't been able to find anything. It's probably just over my head. The problem is that I have a <li> which includes a nested <ul> with it's own <li>'s. I want to select the original <li>, but can't seem to do it without also selecting the nested <ul>'s <li>s....
6
559
by: B0nj | last post by:
I've got a class in which I want to implement a property that operates like an indexer, for the various colors associated with the class. For instance, I want to be able to do 'set' operations like MyClass.MyColors = Color.Green or, a 'get', such as Color forecolor = MyClass.MyColors; I want to use an indexer so I can take parameters, such as the color type (e.g. "Foreground", "Background" etc.). With a single member function I couldn't...
8
16926
by: Robert W. | last post by:
I've almost completed building a Model-View-Controller but have run into a snag. When an event is fired on a form control I want to automatically updated the "connnected" property in the Model. This works fine if all of the properties are at the top (root level) of the model but I'd like to keep them in nested classes to organize them better. So, for example, part of my data model looks like this (simplified) : public class MainClass
2
2047
by: Bob Day | last post by:
Using VS2003, VB.NET, MSDE... I am looking at a demo program that, to my surprise, has nested classes, such as the example below. I guess it surprised me becuase you cannot have nested subs, and I am not sure why you would want nested classes anyway. Is there a URL that explains the advantages to nested classes, when they would be used, etc? What are your thoughts? Also, if a Class has nothing before it (i.e. no Public or Private,...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10631
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10374
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10114
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9196
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.