A brief analysis of the four import methods and priorities in CSS

A brief analysis of the four import methods and priorities in CSS

First: 4 ways to introduce CSS

There are four ways to introduce CSS: inline style, embedded style, link style, and import style.

1. Inline styles

The most direct and simplest one is to use style="" directly on the HTML tag, for example:

<p style="color:#F00; "></p>

Disadvantages: HTML pages are not pure, the file size is large, it is not conducive to spider crawling, and the subsequent maintenance is inconvenient.

2. Inline styles

Inline style means writing CSS code between <head></head> and declaring it with <style></style> , for example:

<style type="text/css">
body,div,a,img,p{margin:0; padding:0;}
</style>

Advantages and disadvantages: The page uses public CSS code, which must be defined for each page. If a website has many pages, each file will become larger and difficult to maintain later. If there are few files and not much CSS code, this style is still very good.

3. Link Style

The link style is the most frequently used and practical style. You only need to add <link…/> between <head></head> , as follows:

<link type="text/css" rel="stylesheet" href="style.css" />

Advantages and disadvantages: It realizes the complete separation of page framework code and presentation CSS code, making pre-production and post-maintenance very convenient

4. Import style (not recommended)

Importing styles is similar to linking styles. The @import style is used to import CSS style sheets. When HTML is initialized, it will be imported into the HTML or CSS file and become part of the file, similar to the second embedded style.

@import is used in HTML as follows:

<style type="text/css">
@import url(style.css);
</style>

@import is used in CSS as follows:

@import url(style.css);

Second: The priority of four CSS introduction methods

1. Proximity principle

2. In theory: Inline > Embed > Link > Import

3. In fact: embedding, linking, and importing are in the same file header, whichever is closer to the corresponding code has a higher priority

Experience:

1. If the same CSS definition is distributed in two CSS files, the style is taken from the CSS file introduced later.

2. It is best to put the CSS of third-party components in the front of HTML and the customized CSS in the back of HTML.

Summarize

This concludes this article on the four import methods and priorities in CSS. For more information on the priority of CSS import methods, please search previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<:  The process of building and configuring the Git environment in Docker

>>:  Vue implements mobile phone verification code login

Recommend

Install .NET 6.0 in CentOS system using cloud server

.NET SDK Download Link https://dotnet.microsoft.c...

Docker starts in Exited state

After docker run, the status is always Exited Sol...

Vue component organization structure and component registration details

Table of contents 1. Component Organization 2. Co...

What you need to know about msyql transaction isolation

What is a transaction? A transaction is a logical...

Common symbols in Unicode

Unicode is a character encoding scheme developed ...

Summary of @ usage in CSS (with examples and explanations)

An at-rule is a declaration that provides instruc...

JavaScript event capture bubbling and capture details

Table of contents 1. Event Flow 1. Concept 2. DOM...

Setting up shared folders in Ubuntu virtual machine of VMWare14.0.0

This is my first blog post. Due to time constrain...

CSS animation property usage and example code (transition/transform/animation)

During development, a good user interface will al...

Responsive layout summary (recommended)

Basic knowledge of responsive layout development ...

CSS selects the first child element under the parent element (:first-child)

Preface I recently used :first-child in a project...

Detailed tutorial on installing Docker on CentOS 7.5

Introduction to Docker Docker is an open source c...

Pure CSS to achieve input box placeholder animation and input verification

For more exciting content, please visit https://g...

Detailed process of zabbix monitoring process and port through agent

Environment Introduction Operating system: centos...

Understanding and application of JavaScript ES6 destructuring operator

Table of contents Preface The role of deconstruct...