Precautions for writing Web Front-end code

Source: Internet
Author: User

1. It is best to add a sentence similar

<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">

The Code follows a W3C standard.

The advantage of using this standard is that you don't have to worry about the layout of websites in different browser environments. After using this standard, I tested IE8, FF, and Safari browsers. The results page is displayed normally. In addition, it is found that some bugs in IE itself will not appear after this standard is used. For example, the bug that the height of the IE default div box is greater than the font height will not appear after this standard is followed.

Note that some non-standard code may not work properly. For example, roll1right is available in javascript. innerHTML = roll1left. innerHTML; Code, where roll1right and roll1left are two different div IDs on the webpage. The webpage can work without applying this standard, however, this statement has a bug in W3C standards. The reason is that W3C requires that all variables have a clear value assignment. Therefore, you must add var roll1right = document before this statement. getElementById ("roll1right"); statement, and then all the code will work normally.

2. when using div and table on a webpage, we found that, although the border, margin, and padding values of div and table can also be set to 0 through css, while div is normal, table still has some gaps. After querying W3CSchool, we found that the original table has two attributes: cellpadding and cellspacing. The cellpadding attribute specifies the gap between the cell edge and the content, while the cellspacing attribute specifies the gap between cells. Therefore, the cellpadding and cellspacing attributes of the table in the webpage are set to 0. As a result, there is no gap between the table in the webpage and the problem is solved.

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.