The following three methods are commonly used to define CSS in HTML: Embedding, Linking, and Inline 1. Embedded Use the HTML style element to define CSS styles in a document. Copy code The code is as follows:<head> <style type="text/css"> h1{color:red} p{color:blue} </style> <head> 2. Inline Every HTML element contains a style attribute, which can directly define the style. This style applies only to the content of this element and has no effect on another element with the same name. Copy code The code is as follows:<p style="color:#FFF;font-weight:bold;">Inline style</p> 3. External reference External reference means that the HTML document itself does not contain CSS styles, but dynamically references external CSS files to define the document's presentation. 1. Use style sheet processing instruction statements Write a style sheet instruction at the beginning of the HTML document Copy code The code is as follows:<?xml-stylesheet type="text/css" href="mystyle.css" ?> <html> Instruction Statement </html> However, only HTML documents written in XML syntax format support the use of this directive. Most browsers are only effective when saved in XHTML or XML format, and JS cannot process this kind of CSS, so it is not recommended. 2. Use @import command Use the @import command between style elements to import external CSS files Copy code The code is as follows:<head> <style type="text/css"> <!--The following two lines of code have the same effect @import "mystyle.css"; @import url("mystyle.css"); --> </style> </head> Any @import rules must appear before all other @import rules. The parameter is the URL of a css file. You can also use the @import directive in a css file to import another css file. 3. Use the link element Copy code The code is as follows:<head> <link rel="stylesheet" href="css的url" type="text/css" > </head> This is also the most commonly used method. 4. Use HTTP message headers to link to style sheets You can use the link field of the HTTP message header to link to an external style sheet. Copy code The code is as follows:link:<mystyle.css>;rel=stylesheet; //Equivalent to <link rel="stylesheet" href="css的url" type="text/css" > Multiple links can be used in the HTTP header to link multiple style sheets, and the link in the HTTP header has priority over the link in the HTML document (in the head element). |
<<: The whole process of IDEA integrating docker to deploy springboot project
>>: CSS float property diagram float property details
Table of contents In the React official website, ...
[Problem description] Our production environment ...
What is Docker-Compose The Compose project origin...
The Raspberry Pi model is 4b, 1G RAM. The system ...
Demand background A statistical interface, the fr...
1. Install libfastcommon-1.0.43. The installation...
Compatible with new CSS3 properties In CSS3, we c...
Preface 1. This article uses MySQL 8.0 version Co...
Ⅰ. Problem description: Use CSS to achieve 3D con...
HTML is a hybrid language used for publishing on ...
Awk is an application for processing text files, ...
<br />Original text: http://andymao.com/andy...
CSS3 can change the color of pictures. From now o...
Recently Microsoft released Windows Server 2016, ...
Introduction to HTML HyperText Markup Language: H...