473,603 Members | 2,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

basic descendant selector question

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 }

so my questions....

1. can i shorten td#advert to just #advert?

2. can i shorten tr td#sidetop to just #sidetop?

tia -
Mr T.
Jul 20 '05 #1
11 2022
On Wed, 16 Jun 2004 19:11:51 -0700, Laurence Tureaud wrote:
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 }

so my questions....

1. can i shorten td#advert to just #advert?
Yes, but it's only recommended if either the holder of the 'advert' ID
will never change or all the styles are relevant to any possible 'advert'
element. Keep in mind an ID may be used more than once on different pages.
2. can i shorten tr td#sidetop to just #sidetop?


Decide for yourself by working out which elements on which pages the
former and the latter select and then determining if the difference is
relevant.

--
Some say the Wired doesn't have political borders like the real world,
but there are far too many nonsense-spouting anarchists or idiots who
think that pranks are a revolution.

Jul 20 '05 #2
Laurence Tureaud wrote:
td#advert {stuff}
#content-top td { stuff }
tr td#sidetop {stuff }

1. can i shorten td#advert to just #advert?
This depends on the context. td#advert selects only <td> elements
whose id="advert", while #advert selects any element whose
id="advert". Will another page have <div id="advert">? Do you want the
style to apply to both?
2. can i shorten tr td#sidetop to just #sidetop?


I'm not sure about the point of tr. A <td> element is *always* a
descendent of <tr>, so it seems superfluous. But beyond that, the same
question applies. What do you want to style? <td id="sidetop">? Or any
element whose id="sidetop"?

--
Brian (remove ".invalid" to email me)
http://www.tsmchughs.com/
Jul 20 '05 #3
On Thu, 17 Jun 2004 02:14:22 GMT, Owen Jacobson
<an******@lions anctuary.net> wrote:
1. can i shorten td#advert to just #advert?


Yes, but it's only recommended if either the holder of the 'advert' ID
will never change or all the styles are relevant to any possible 'advert'
element. Keep in mind an ID may be used more than once on different
pages.

aha.. but an ID should be used only once on any given page, right?
because a book i'm reading "dreamweave r 2004 mx missing manual" says an
ID is for formatting a unique item on a page.

I understand what you say about multiple pages though.

thanks-
matt
Jul 20 '05 #4
pi*********@gma il.com (Laurence Tureaud) wrote:
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 }

so my questions....

1. can i shorten td#advert to just #advert?
Yes, if the element with id="advert" on your pages is always a TD.

2. can i shorten tr td#sidetop to just #sidetop?


Likewise. The tr seems especially pointless since you can't have a TD
that isn't inside a TR.

--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ôter le premier point de mon adresse de courriel.
Jul 20 '05 #5
"Laurence Tureaud" <pi*********@gm ail.com> wrote:
On Thu, 17 Jun 2004 02:14:22 GMT, Owen Jacobson
<an******@lion sanctuary.net> wrote:
1. can i shorten td#advert to just #advert?


Yes, but it's only recommended if either the holder of the 'advert' ID
will never change or all the styles are relevant to any possible 'advert'
element. Keep in mind an ID may be used more than once on different
pages.

aha.. but an ID should be used only once on any given page, right?


Right.
--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ôter le premier point de mon adresse de courriel.
Jul 20 '05 #6
ok good. i think i'm getting this stuff.
This depends on the context. td#advert selects only <td> elements whose
id="advert", while #advert selects any element whose id="advert". Will
another page have <div id="advert">? Do you want the style to apply to
both?

but wouldn't it be a bit sloppy to use the same id name in different
places?

are there any performance related issues with either approach? i thought
maybe using a more specific path would speed the application of the style.

thanks again-
matt
Jul 20 '05 #7
Laurence Tureaud wrote:
an ID should be used only once on any given page, right?
Yes. But it can be used on a different page on the same site, and both
pages could (and normally would) use the same stylesheet.
a book i'm reading "dreamweave r 2004 mx missing manual" says an
ID is for formatting a unique item on a page.


Well that definition seems rather limiting. The id attribute is meant
to be used as a fragment identifier for urls; it can also be used in
css selectors, in javascript, and probably for other things I cannot
think of. You might want to find something more reliable than a
Dreamweaver manual to explain www terminology.

--
Brian (remove ".invalid" to email me)
http://www.tsmchughs.com/
Jul 20 '05 #8
Laurence Tureaud wrote:
ok good. i think i'm getting this stuff.
This depends on the context. td#advert selects only <td> elements
whose id="advert", while #advert selects any element whose
id="advert". Will another page have <div id="advert">? Do you want
the style to apply to both?
wouldn't it be a bit sloppy to use the same id name in different
places?


No, not at all. It's nearly ubiquitous for every page of a site to
have a navigation section, and quite common for the container of said
navigation to have id="nav" or something similar, on every page of the
site.
are there any performance related issues with either approach? i thought
maybe using a more specific path would speed the application of the style.


I know of no studies to suggest any difference in document rendering
by using id instead of, say, class or element selector.

--
Brian (remove ".invalid" to email me)
http://www.tsmchughs.com/
Jul 20 '05 #9
Laurence Tureaud wrote:
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 }

[snip]

You've received lots of good answers. But I wonder if there is something more?
Have a look at these posts by Eric in response to queries like this elsewhere.
(It is to do with maximising specificity in certain cases).

http://groups.google.com/groups?selm...macromedia.com

http://groups.google.com/groups?selm...macromedia.com

--
Barry Pearson
http://www.Barry.Pearson.name/photography/
http://www.BirdsAndAnimals.info/
http://www.ChildSupportAnalysis.co.uk/
Jul 20 '05 #10

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

Similar topics

6
2320
by: Richard Barnet | last post by:
Dear CSS gurus, My question regarding 'the cascade' is a simple one, but one that I haven't heard anyone talk about before: When cascading (for instance, when applying two linked stylesheets), does the whole selector definition supercede and replace a previous one, or does it go through the selector definition line by line (rule by rule) and only supercede rules and attributes that are previously defined?
2
3855
by: tagbert | last post by:
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...
7
2315
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.
2
8548
by: Andrew Poulos | last post by:
If I have some HTML that looks like this: <div class="option"> <table> <tbody> <tr> <td>blah</td> <td>blah</td> </tr> </tbody>
5
1964
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
2
1836
by: olivier_henley | last post by:
hi to all, let say I have a html div which id is 'mydiv'. In the style, I change the #mydiv properties dynamically. After those changes have been made, I would like to keep them intact but just change the id selector name. E.g. the new name could become #mydiv2. I need this to reference this precise new id selector name later on. thank you for your help. Don't hesitate to ask question if you feel my explanations are unclear.
5
1542
by: KiwiBrian | last post by:
I have a php series of scripts/programs/files which provide a simple calendar/scheduler program. When either an email or web address/hyperlink are displayed within the output, they seem to have the browser default link colours and underline. Altho the output table/content is within a div in the web page, I seem to be unable to apply CSS styles to the div contents in this case. I have even tried !important to no avail. There does not seem...
6
7189
by: _googlepost | last post by:
I have some CSS that goes something like this: table.TableStyle {font-family: "Helvetica", "Ariel"; background- color:white; border-collapse:collapse;} table.TableStyle COLGROUP { background- color:lavender;} The second line is a style that is applied to a particular named COLGROUP element in tables assigned the TableStyle class. Unfortunately, while this works in most modern browsers (including
6
1283
by: soni2926 | last post by:
hi, what's the difference between using . or #? #switcher { .... } ..chapter { ..... }
0
7996
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
7928
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8415
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...
0
8405
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8060
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
6735
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
5878
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
5441
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1514
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.