Can we use <body> instead of the #container div?
Is it possible to set width and border to <body> and use div instead of Container? see this example
see the source code of this file, and the file code is also great for W3C. and look the same in IE 7 and firefox 3.5.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" dir="ltr"> <head> <title> Width in body</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <style type="text/css"> html { background-color: #00f; } body{background: #cd5c5c;width:800px;height:400px;border:1px solid;color: #fff;margin:0 auto;} </style> </head> <body> <p>Hello world!</p> </body> </html> +6
Jitendra vyas
source share1 answer
Your example answers your question! The body is an element of the block, like any other. It has width, height, padding, field properties and borders.
- Please note that it is important that the page is displayed in strict mode and not in quirks mode in order to be able to treat the body element as a block-level element; otherwise, it is treated as a documentElement, and all bets are disabled. - NickFitz
Then can we use the body instead of the #container div? - jitendra
- Good theory. Shame on Microsoft. - David Dorward
- @Jitendra: you can, but be careful with your cross-browser testing, especially when it comes to scrolling :-) - NickFitz
What is the difference between the viewport and the body? - jitendra
- The viewing area is the visible area of ββthe browser window that displays the document. The body is an element of the document. In quirks mode, the body will also be considered as documentElement: that is, the root node of the document, which will fill the window, and will scroll if necessary. In strict mode, the html element will be treated as a documentElement, and the body will be a child. As an experiment, modify the test page by adding an html style rule {background-color: # 00f; } - you will see that the html element contains `body '- NickFitz
+7
deau
source share