Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2009
    Location
    Earth - sometimes sky :-)
    Posts
    121
    Thanks
    51
    Thanked 2 Times in 2 Posts

    What is the difference between .header or #header in CSS

    I wish to figure out the difference between .header and if I write #header rules in a CSS file. I mean this content in a CSS file:

    .header {
    margin-left: auto;
    margin-right: auto;
    ....
    }

    and this

    #header {
    margin-left: auto;
    margin-right: auto;
    ....
    }

    What is the difference?

  • #2
    New Coder
    Join Date
    May 2005
    Location
    Cebu, Philippines
    Posts
    46
    Thanks
    1
    Thanked 10 Times in 10 Posts
    "." points to a class
    "#" points to an id

    example:

    <div id="header">
    Header ID DIV
    </div>

    <div class="header">
    Header Class DIV
    </div>


    your .header style will affect the second example
    and your #header style will affect the first.

  • Users who have thanked JygzIsHere for this post:

    joda (05-14-2009)

  • #3
    Senior Coder twodayslate's Avatar
    Join Date
    Mar 2007
    Location
    VA
    Posts
    1,042
    Thanks
    67
    Thanked 39 Times in 39 Posts
    twitter | Quality Hosting - $5.95/mo*
    Feel free to PM me!

  • Users who have thanked twodayslate for this post:

    joda (05-14-2009)

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    joda (05-14-2009)

  • #5
    Regular Coder
    Join Date
    May 2008
    Location
    Oxford, UK
    Posts
    422
    Thanks
    14
    Thanked 27 Times in 27 Posts
    it's all in those links I'm sure but if you can't be bothered reading them it's worth pointing out that an ID should be unique and can only be used once, classes can be used as many times as you like

  • Users who have thanked brazenskies for this post:

    joda (05-14-2009)


  •  

    Posting Permissions

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