SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Oct 2006
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    noob: css declaration #content vs div#content?

    Are they the same?

  2. #2
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    basically yes. An id can only be applied to one element per page, so it's going to be a div.

    There is a situation where they'd be very different. If you're using an external stylesheet and on some pages #content is the id of a div and on some pages it's not. In that case #content would implement style rules that you want to apply anywhere you use id="content", regardless of the element it's attached to. And div #content would be the style rules that only apply to divs with the content id.
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    md
    Posts
    180
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Chroniclemaster1 View Post
    basically yes. An id can only be applied to one element per page, so it's going to be a div.

    There is a situation where they'd be very different. If you're using an external stylesheet and on some pages #content is the id of a div and on some pages it's not. In that case #content would implement style rules that you want to apply anywhere you use id="content", regardless of the element it's attached to. And div #content would be the style rules that only apply to divs with the content id.
    How do you know it will be a div and not an anchor link or image?

  4. #4
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    If it is "div #content" it means "a div element with the id content", where as "#content" is "any element with the id content".

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it is "div #content" it means "a div element with the id content"
    Not sure if this is a typo or not. But, "div #content" (note the space) means any element that is contained in any div and has an id of "content".

    div#content is what you described: "a div element with the id content"

    John

  6. #6
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    Oops, yup, that was a typo.

    "div #content" would mean "An element with the id of content contained within a div, regardless of how deep"

    And, while we're at it "div>#content" would mean "An element with the id of content contained directly within a div"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •