Ze Carioca Silva
Ze Carioca Silva

Reputation: 443

What is the difference beetween body and #body

In my code I have this:

#body {
    background-color: #efeeef;
    clear: both;
    padding-bottom: 35px;
}

And this:

body {
    background-color: #fff;
    border-top: solid 10px #000;
    color: #333;
    font-size: .85em;
    font-family: "Segoe UI", Verdana, Helvetica, Sans-Serif;
    margin: 0;
    padding: 0;
}

My doubt is because # is an ID selector, but body isnt an ID.

Upvotes: 0

Views: 1091

Answers (4)

Elias Zan
Elias Zan

Reputation: 157

#body is selecting an id named body, so if you had a it would make changes inside that div, while body would make change

Upvotes: 0

Quentin
Quentin

Reputation: 944443

My doubt is because # is an ID selector, but body isnt an ID.

Is is now:

<div id="body">...</div>

IDing elements after element types isn't a great idea (since it can be confusing), but it is legal.

Upvotes: 2

Chris Doggett
Chris Doggett

Reputation: 20777

#body refers to any element, not just a body element, that has the id attribute set to "body".

The second one refers to the body tag.

Upvotes: 0

karthikr
karthikr

Reputation: 99680

#body refers to an element with id body and body refers to <body .... of HTML

Example: you could give a <div id="body"> and the CSS for #body would apply to the div.

Upvotes: 5

Related Questions