HTML and body tags apply CSS methods and techniques

Source: Internet
Author: User

We all know that for a page, the most basic structure is

<!--head information content area-->
<body>
<!--page display content area-->
</body>

For such a structure, no one will feel unfamiliar, but often sometimes it is the more familiar things are easy to let people forget their existence. You may be thinking, what is the structure of these tags to talk about, each page needs their AH. Yes, I have always thought so, but recently found that in fact, in many cases, these obscure we do not care about the label can help us in the process of beautifying the page to bring a lot of help.

As for hack, we all know that HTML and *+html can help us identify between IE7 and IE6, which is not what I want to say now. In fact, I would like to say that the content is very simple, mainly have the following points.

1. Using HTML background, we can reduce the addition of a DIV tag to include all the contents of the body in more time, and the HTML as the parent of the body, so the background (background color and background picture, the following "background" appears) Two words are the background color and background pictures will be covered by the background of the body, first look at a small piece of code we continue to chat

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<meta http-equiv= "x-ua-compatible" content= "Ie=emulateie7"/>
<style type= "Text/css" >
#myHtml {background-color: #CCCCCC;}
#myBody {background-color: #FF0000;}
</style>
<title> Untitled Document </title>
<body id= "Mybody" >
Xiao Zhi reminder: Try to delete the text in the body before doing a simple contrast, do not forget the browser difference Oh.
</body>

Through a small piece of code above, you can see the background of the body and the HTML background of the difference between it. Then you should be able to think of the background since this feature, we can consider sometimes when dealing with some background images of the background also use the HTML, especially in dealing with some of the more personalized pages (such as game website).

Ps:

A. If you remove the HTML (#myHtml) style, and you look at the browser's performance, you will find that the world has changed.

B. Settings for background colors also allow browser-customized background colors to be invalidated (IE7: Tools-> "Internet Options"-> "General" colors in which you can find settings for backgrounds)

2, in the upper part of the code does not use the direct settings

HTML {background-color: #CCCCCC;}
Body {background-color: #FF0000;}

Instead of using two IDs, I don't know if you're wondering why I'm doing this. There are several ways to consider this.

2.1 JS calls (relatively speaking, using more than a bit of the body using the ID or Class)

2.2 The elevation of privilege values in CSS (this is basically a very slim chance to use)

Simply say what we can do if the body uses ID or class.

A. For now the network appears in the page, we can see a lot of times, a navigation is highlighted, prompted you are currently browsing on which page. The function of this is that I can use the body or that navigation to add an ID or class to judge the recognition, of course, add a style to this ID or class.

B. In some of the larger sites, the approximate structure of a channel or some channel is the same, so we can use one of the structure as the basis of reference, copied to other pages used, and then call the same style, which can reduce a lot of duplication of work, but also make the structure of the page more reusable, as a difference we just use the body ID or class to modify the weight value of the style is OK. This may be more confusing, we can roughly refer to the thunder of the animation channel http://anime.xunlei.com/(but this channel in the body of the use of too much class and relatively messy, this is a failure of it)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.