0

Possible Duplicate:
Should global css styles be set on the html element or the body element?

There's some really interesting discussion about applying CSS to <html> and <body> in order to get some cool effects — like two background images, one transparent (but CSS3 may render that useless).

However, for the standard cases, which element is most appropriate to use for appling page-wide CSS to?

Perhaps there's even some CSS properties that are better suited to one selector over the other? Thus, split among the two?

(This concerns things like cross-browser compatibility, as well as proper semantics according to spec.)

And we can also bring the wildcard * { } selector into this discussion.

Community
  • 1
  • 1
Baumr
  • 6,124
  • 14
  • 37
  • 63
  • 1
    Related: [What's the difference in applying CSS to html, body, and *?](http://stackoverflow.com/q/7187569) – Pekka Oct 28 '12 at 15:44
  • 1
    @Pekka: That was already linked in the question ;) – BoltClock Oct 28 '12 at 15:53
  • @BoltClock oops, my bad. – Pekka Oct 28 '12 at 15:54
  • 1
    I don't think the universal selector fits within the scope of this question (you can see how hard I'm trying to avoid calling it a discussion...). – BoltClock Oct 28 '12 at 15:55
  • 1
    @Baumr: I finished editing my answer (finally). If it answers your question, and you feel that the questions are the same, feel free to flag your question as a duplicate. – BoltClock Oct 28 '12 at 17:52
  • Perfect answer, feel free to link to it as a reply and I can mark it as the solution here? (Don't know what the policy here is.) – Baumr Oct 28 '12 at 17:54
  • No problem. Questions that are the same as others are typically closed as duplicates with a link to the older question at the very top, rather than having an answer to the earlier question simply linked to newer one at the bottom. – BoltClock Oct 28 '12 at 20:02

3 Answers3

1

Following Verandaguy's answer, http://www.w3.org/Style/Examples/011/firstcss.en.html applies the style to the body. It doesn't say why, but, that's what it says.

ChrisW
  • 54,973
  • 13
  • 116
  • 224
  • 3
    That's just an example, though, which is therefore non-normative. That might explain why it doesn't explain why (try saying that 5 times fast). Another tutorial can be found in the spec: http://www.w3.org/TR/CSS21/intro.html but it's also non-normative. – BoltClock Oct 28 '12 at 16:49
0

I believe that the W3C recommends that you apply any page-wide styles to the <body> element.

Jules
  • 14,200
  • 13
  • 56
  • 101
-1

For creating a site with several pages it is best to use the CSS as an external linked page. That way each page can have access to it. But for a single page to page, it would be a "cool effect" on some browsers. But in the same effect other computers might see those effects in a different and less rendered method. Stick with uses the CSS mostly as an external link, and use style tags only as needed, or leave a note on the page of how and what browser they are supposed to view it on.

mr.j05hua
  • 170
  • 4
  • 14