Principles for HTML page output

Source: Internet
Author: User

The DOCTYPE cannot be missing. The browser determines the page rendering rules based on the DOCTYPE you declare. If it is not declared, different browsers may display different effects. Add the <meta> label before <title> to describe the code used on the page. Otherwise, the title of Some browsers may be garbled.

<Style> should be placed in the Avoid using expressions in CSS. Otherwise, the browser recalculates the expression value every time the page content changes (for example, javascript dynamically adds or deletes elements and changes the browser window size. One alternative method is to use javascript to dynamically judge and confirm the style in window. onload. We should also cherish the resources of the user end.

When using javascript to change the Display Effect of page Meta, use the className attribute whenever possible. Avoid using statements such as element. style. color = "# ff0000", especially when changing attributes multiple times at a time. There are two reasons for doing so: facilitating maintenance and saving client resources. When you use className to change a page, you only need to re-render the page once, and when the style attribute is changed, re-render the page every time, which is much higher than the overhead.

The <script/> label should be placed before the </body> label. When the browser downloads the content in <script>, it does not download other content (images, flash, html files after <script>) at the same time. If a large number of external script files are used, this may result in loss of support and continues to wait for the patience displayed on the page.

A simple example:

Copy to ClipboardReference: [www.bkjia.com] <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> demonstration bkjia.com </title>
<Meta name = "keywords" content = "test, demonstration"/>
<Link rel = "Stylesheet" type = "text/css" href = "common.css"/>
<Style type = "text/css">
. Test {border: 1px solid # ff0000 ;}
. Dom {width: 200px; height: 100px ;}
. Notdom {width: 202px; height: 102px ;}
</Style>
</Head>
<Body>
<Div id = "main" class = "test"> </div>
<Script type = "text/javascript" src = "jquery. js"> </script>
<Script type = "text/javascript">
$ (Function (){
If ($. support. boxModel ){
$ ("# Main"). addClass ("dom ");
} Else {
$ ("# Main"). addClass ("notdom ");
}
});
</Script>
</Body>
</Html>

 

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.