HTML5 three ways to combine CSS + three ways to combine JS

Source: Internet
Author: User

HTML5+CSS:

Three ways to apply CSS in HTML

First, inline

Inline styles are directly nested into HTML through the Style property.

Sample code

    1. <pstylepstyle="color:red">text</P>

This will be the specified paragraph turns red. Our suggestion is that HTML should be a standalone, free-form document, so inline styles should be avoided whenever possible.

Second, internal

The internal style serves the entire current page. Inside the head tag head, the style label style contains all the styles of the current page.

Sample code

  1. <! Doctypehtmlpublic "-//w3c//dtdxhtml1.0strict//en"
  2. "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html>
  4. <head>
  5. <title>cssexample</title>
  6. <styletypestyletype="Text/css">p{color:red;} A{color:blue;} </style>
  7. </head>
  8. <body>
  9. </body>
  10. </head>
  11. </html>

This will make all the paragraphs in this page red, and all the connections are blue. Similar to inline styles, it is also not recommended.

Third, external

The external style serves multiple pages for the entire site. This is a standalone CSS document, a simple example of the following:

Sample code

    1. p{color:red;} A{color:blue;}

If the document is saved as "web.css", it can be connected to an HTML document like this:

Sample code

  1. <! Doctypehtmlpublic "-//w3c//dtdxhtml1.0strict//en"
  2. "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html>
  4. <head>
  5. <title>cssexample</title>
  6. <Linkrellinkrel= "stylesheet"type= "text/css"href="web.css"/>
  7. </head>
  8. <body>
  9. </body>
  10. </head>
  11. </html>

Save the HTML document, now the HTML and CSS are connected, in your HTML can be used in your CSS file defined in the CSS tag.

Html5+javascript:

Three ways to apply JS in HTML

One, the HTML5 page uses the <script> tag to accommodate the JavaScript code;

123 <script>   init();</script>

Not only can you call functions of any location, but you can declare variables, build functions and objects, and so on.

Second, the HTML5 page uses the <script src= "Xxx.js" ></script> introduces the JavaScript code in the Xxx.js file under the same path;

1 <script src="js/main.js"></script>

Note that this main.js is the same directory as the current Html page file in the JS subdirectory of the file, when used to ensure that the relative path is correct, of course, you can also use absolute path.

Third, the HTML5 interface element event is directly assigned to a section of JavaScript code;

1 <input type="button"name="Button" value="Button"onclick="javascript:alert(‘测试‘)">

Here you can refer to the JavaScript settings onclick

HTML5 three ways to combine CSS + three ways to combine JS

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.