Results 1 to 5 of 5

Thread: Div ID containers and .class attributes?

  1. #1
    Join Date
    Apr 2008
    Posts
    109
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Div ID containers and .class attributes?

    Hello!

    I have a very simple question to ask.

    I mainly use Dreamweaver for creating websites, and I have noticed that some others use Div ID's and classes in the same selector.

    Looks like this; #main .lftfloat

    The above is a Div ID container named 'main', and a .class attribute named .lftfloat... correct?

    My question is then, when people can create the same rules and designs inside the Div ID container, why do they also associate a .class attribute to it, when they really both do the same?


    Cheers,
    Bassa

  2. #2
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Default

    the class may be a "global" style which they wanted to apply to that certain div. Rather than writing those styles directly to the css for that particular div, they probably just added that class to it as well (which I'm guessing is something which makes the div float left)
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  3. The Following 2 Users Say Thank You to TheJoshMan For This Useful Post:

    jimbob79 (10-14-2008),Maynard (10-12-2008)

  4. #3
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    sometimes people use the ID as a means to help identify a section.
    since an ID can only be used once per page.

    Maybe something like #section1, .tab1 and #section2, tab1.
    This way, tab1 could have two sets of definitions depending on which ID is controlling that area at the moment.

  5. The Following User Says Thank You to vegas1969 For This Useful Post:

    jimbob79 (10-14-2008)

  6. #4
    Join Date
    Oct 2008
    Posts
    10
    Thanks
    12
    Thanked 2 Times in 2 Posts

    Default

    I agree with Nyne, although the ID is and can be used as a way to help "indentify" a section of the page (hence the name "ID"), I think that Nyne hit the nail on the head when mentioning global styles. Though you can style an ID in css just as you can a class, what if you already have a certain set of styles set in a global class? Why write more code than you have to? It's simpler just to apply that class to the ID than write the styles all over again.

  7. The Following User Says Thank You to jimbob79 For This Useful Post:

    TheJoshMan (10-14-2008)

  8. #5
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Default

    that's exactly what I was getting at.
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  9. The Following User Says Thank You to TheJoshMan For This Useful Post:

    jimbob79 (10-14-2008)

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
  •