Tips for writing Web front-end code

Source: Internet
Author: User

1, unless you must otherwise do not use embedded CSS style

You cannot use inline CSS code unless you test your code, or when necessary:

<pstyle= "color:red;" > XI 玬 yarn personal website </p>

Although this writing can not see any problems in the short term, one but error, we will find that the modification is very laborious. In general, our approach is to define the style of the P tag in the style sheet file:

p {color:red;}

2, the use of JS outside the chain file, to achieve the structure of the three-style behavior separation, or try to write JavaScript code at the bottom of the HTML code. Or use the Window.onload event

If you just open the page to load a JS script language will occupy the entire page load time, resulting in slow loading of the Web page, the user experience is poor.

But JS simply implements simple, single events, such as simple click-button events. Then just refer directly to the body tag.

Example:

<scripttype= "Text/javascript" id= "Bdshare_js" Data= "type=tools&amp;uid=6574585" ></script>

<scripttype= "Text/javascript" id= "Bdshell_js" ></script>

</body>

3, learn and make good use of h1-h6 tags, so that your site is easily included.

It is recommended that you use all six kinds of tags in the Web page, although most people will only use the first four, but the use of the most h will have a lot of benefits, such as equipment friendly, search engine friendly and so on, you can replace the P tag for H6.

4, if the personal blog site, we learn to leave the H1 tags to the article title

Of course the specific how to use depends on your needs, but I suggest you build a blog, the article title as H1, which for search engine optimization (SEO) is very good.

5, learn how to deal with IE

IE has long been a nightmare for front-end developers. If your CSS style sheet is basically stereotyped, then you can create a stylesheet for IE, which is only valid for IE:

<!--[If Lt IE 9]>

<scriptsrc= "/skin/blog/js/modernizr.js" ></script>

<! [endif]-->

The code means: if the user's browser is IE9 and below, then this code will not take effect.

6, to reduce their div

Looking back at the first page that most of us have written, we will definitely find a serious "div fetish" (divitis), usually a beginner's instinct is to wrap a paragraph in div and then put more div in place to control the location. It's actually a inefficient and harmful way of learning to adapt and use the right label.

After the page is finished, be sure to check back several times to minimize the number of elements. Can use the list of UL layout do not use a div to layout.

7, to add ALT attributes to the picture need to be compatible with Firefox browser can add title attribute

The benefits of adding Alt attributes to a picture are self-evident-this allows users who disable pictures or use special devices to have access to information about your Web page and to search engine friendly images. Firefox does not support the display of image Alt properties, you can add title Properties < All can make the mouse pass the image of the picture when the annotation >

8, learn to view the source code of excellent website, and download to save. Good at Learning

Nothing can make you learn HTML faster than imitating your idol. At first, we all want to do the copier, and then slowly have to develop their own style. Study your favorite Web page code to see how they are implemented. This is the only way to master, you must try. Note: Just learn and imitate their coding style, not plagiarism and copying. Watch out for all the cool JavaScript effects on the web, and if it looks like you're using a plugin, you can find the plugin name based on the file name in the head tag in the source code, and then you can learn it for your own use.

9, obviously, all of the tags have their own unique default style, learn to write the page for all the labels before the style definition

This one is especially necessary when you are making other corporate websites. You do not use the blockquote tag yourself. That user may use, you do not use OL. Users may also be. Take the time to make a page that shows the style of Ul,ol, p, h1-h6,blockquotes, and so on, and check for omissions.

All text between <blockquote> and </blockquote> is separated from the regular text, often indented on both the left and right sides (increasing the margins), and sometimes italic is used. In other words, block references have their own space.

10. Use CSS Reset

Each browser has its own or common default style, will cause some of the layout of the puzzle, the role of CSS reset is to reset these default styles, so that the style performance consistent, such as *{margin:0;padding:0} is a simple CSS Reset resets these default styles to match the style, such as *{margin:0;padding:0} is the simplest CSS reset

The author provides a common style:

body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td{margin:0; padding:0;}
Body{background: #e8f0ff;}
table{border-collapse:collapse;border-spacing:0;}
fieldset,img{border:0 none;
Address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}
strong{font-weight:800;}
Ol,ul,li{list-style:none outside none;
Caption,th{text-align:left;}
H1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}


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.