Grow your CSS skills. Land your dream job.

required: div class or id ?

  • # January 18, 2011 at 10:07 pm

    hey , just wondering, im making just a quick runndown static website and using html5. but remembered that in one of my previous posts that the HTML 5 wasn’t cross browser proper for me. i dont know it was mental!

    but here’s the code. so far

    < !DOCTYPE html>











    This is the website title Inside the header


    This is the some quote or sloagen







    This may change per page.


    This may change per page.


    This may change per page.


    This may change per page.





    This is your footer copywrite section.






    so my real question was, should i be naming every div? (giving it an “ID” or “Class”?? if so ? howcome
    or why not?
    and is it good practice?

    # January 18, 2011 at 10:18 pm

    XHTML

    HTML5

    Also, HTML5 has

    so you dont have to use your #main-content div.

    I usually only give main sections an ID and use classes for little things within the ID.

    # January 18, 2011 at 10:21 pm

    oh sweet!!!! thank you!!

    # January 18, 2011 at 10:50 pm

    So, heres what the difference between classes and IDs are.

    IDs are used for elements that don’t repeat (ones that you only have one of) such as #footer
    Classes are used for repeating things such as an LI element inside of a UL.

    Your code wont validate if you have more than one of the same ID on the same page.

    Hope that helps

    # January 18, 2011 at 11:23 pm

    no no i mean

    do you have do give a div an ID or class?
    like, is it also best practice to leave a few blank? or no

    Rob
    # January 19, 2011 at 2:42 am

    You don’t HAVE to – depends what you want to do really.

    # January 19, 2011 at 4:12 am

    You don’t have to give it anything apart from the name

    however I fell it helps to know what the point of the div is for or how it is to be styled and so give it a meaningful id or class
Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".