Three common ways to embed CSS in HTML documents

Three common ways to embed CSS in HTML documents
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

Recommend

How to set a dotted border in html

Use CSS styles and HTML tag elements In order to ...

Vue implements scrollable pop-up window effect

This article shares the specific code of Vue to a...

Solution to the problem of null column in NOT IN filling pit in MySQL

Some time ago, when I was working on a small func...

How to create users and manage permissions in MySQL

1. How to create a user and password 1. Enter the...

Three ways to check whether a port is open in a remote Linux system

This is a very important topic, not only for Linu...

Detailed process of installing and configuring MySQL and Navicat prenium

Prerequisite: Mac, zsh installed, mysql downloade...

Introduction to query commands for MySQL stored procedures

As shown below: select name from mysql.proc where...

Example method of deploying react project on nginx

Test project: react-demo Clone your react-demo pr...

Detailed explanation of Mysql logical architecture

1. Overall architecture diagram Compared to other...

JavaScript quickly implements calendar effects

This article example shares the specific code of ...

Initial settings after installing Ubuntu 16 in the development environment

The office needs Ubuntu system as the Linux devel...

MYSQL updatexml() function error injection analysis

First, understand the updatexml() function UPDATE...