Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7
  1. #1
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Hey, I have seen the following css statement and not really sure of it's purpose.

    HTML Code:
    html>body, html>body div, html>body p, 
    html>body th, html>body td, 
    html>body li, html>body dd {
        font-size: small; }
    Is this just a longhand way of writing the following:
    HTML Code:
    body, div, p, th, td, li, dd { font-size: small; }
    If so, which should I use?

  2.  

  3. #2
    Senior Member Shani's Avatar
    Join Date
    Nov 2004
    Posts
    1,140
    Member #
    8171
    I have never seen that either. The shorter version that you have wrote is what I do.
    Shani

    I have an eye for detail like you'd never believe.

  4. #3
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    They're basically equivalent, if only because body tags can only be direct descendants of html tags anyway, and the other tags can't exist except as descendants of the body tag. It seems like those selectors are needlessly specific.

    EDIT: Though the added specificity probably lets it override certain other selectors, i should mention. So it's possible the extra qualifiers are there to give added precedence.

  5. #4
    Junior Member
    Join Date
    Oct 2007
    Posts
    13
    Member #
    16010
    This is the child selector despite Internet Explorer 6 not supporting the CSS child selector, it's actually been used a lot as a way of hiding CSS commands from Internet Explorer. This is no longer possible as IE7 now understands the child selector. To understand, what is the child selector? Imagine the following HTML structure:

    <div><p><span>Text goes here</span></p></div>

    In the above example, the <p> is a child of the <div> and the <span> is a grandchild of the <div>. We can make the text in the <span> red by using the following CSS rule:


    div span {color: red;}


    This basically means that the contents of the <span> will be red, provided that the <span> is nested within a <div>. That <span> could be a child, grandchild, great-grandchild etc. of the <div>.


    If we were however to use the following CSS code:


    div>span {color: red;}


    ...Then the text within our <span> wouldn't turn red. This is because we've inserted the child selector between the div and span (the greater than sign), which basically means that our span has to be a child of a div. In the above example, the <span> is a grandchild of the <div>.


    So, by using the child selector, we can assign rules to any HTML element that's a child (and not a grandchild) of another element. Let's say for example we want a top margin to be assigned to the first <div> in our body, but not to any others. Without the child selector we would be forced to assign a class or id to this <div> and reference that class or id in our CSS command. Now though, we can reference this <div>, and only this <div>, without the need for a class or id through the CSS:
    body>div {margin-top: 10px;}

  6. #5
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Ah, avoiding IE. That one hadn't occurred to me.

  7. #6
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Very briefly:

    The child selector (parent>child) means the child element has to reside directly within the parent element.

    The descendant selector (ancestor descendant) means the descendant element has to reside anywhere in the descendant tree of the ancestor element.

    PS - I always use descendant selectors

  8. #7
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Yeah thats how I roll.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:03 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com