HTML5+CSS:
Three ways to apply CSS in HTML
First, inline
Inline styles are directly nested into HTML through the Style property.
Sample code
- <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
- <! Doctypehtmlpublic "-//w3c//dtdxhtml1.0strict//en"
- "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html>
- <head>
- <title>cssexample</title>
- <styletypestyletype="Text/css">p{color:red;} A{color:blue;} </style>
- </head>
- <body>
- </body>
- </head>
- </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
- 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
- <! Doctypehtmlpublic "-//w3c//dtdxhtml1.0strict//en"
- "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html>
- <head>
- <title>cssexample</title>
- <Linkrellinkrel= "stylesheet"type= "text/css"href="web.css"/>
- </head>
- <body>
- </body>
- </head>
- </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