Home Web Front-end CSS Tutorial The difference between imported style sheet CSS and linked style sheet CSS

The difference between imported style sheet CSS and linked style sheet CSS

Dec 16, 2016 pm 03:37 PM

1

2

3

4

5

6

7

8

<span style="font-family:Arial;"><!-- 链接外部样式:也就是在与<head>与</head>标记之间加入一个<link>标记。 --> 

<head> 

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

</head> 

<!-- 导入外部样式:在内部样式表的<style></style>标记之间导入一个外部样式表,导入时用@import。 --> 

<style type="text/css"

 @import "CssStyle.css"

</style></span>

Copy after login

Because I can’t always tell the difference, I took a look while I still have some time


First of all, let’s distinguish between linking external styles and importing external styles:

We know that these two types of external references The style function is almost the same, both refer to independent CSS style files into web page files, but there are still some subtle differences between the two (because the design will not be boring enough to create two identical ones. things), let’s discuss it based on the two aspects I learned:

1. Using link link css means that when the client browses your web page, it first loads the external CSS file into the web page, and then compiles it. Display, so in this case the displayed web page has the same effect as we expected, even if the network speed is slow, the effect will be the same. The CSS imported using @import is different. When the client browses the web page, it first presents the structure of the html, and then loads the external CSS file into the web page. Of course, the final effect is the same as the former, but when When the network speed is slow, the HTML webpage without CSS unified layout will be displayed first, which will give readers a very bad feeling. This is also the main reason why the CSS of most websites now uses links;

2. Importing styles can avoid too many pages pointing to one css file. When there are not many pages using the same CSS file in the website, there is almost no difference between the two methods in terms of effect. However, when the number of pages on the website reaches a certain level (such as Sina and other portals), it may be difficult to use the link method. This will cause the speed to drop due to multiple pages calling the same CSS file, but generally websites that can reach this level of page will also have the capital to use the best hard disk, so there is no need to worry about this factor.

Based on the above two factors, we can find that most websites now prefer to use links to reference external CSS.


For more related articles on the difference between imported style sheet CSS and linked style sheet CSS, please pay attention to the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It&#039;s out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I&#039;d say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That&#039;s like this.

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

How to Use CSS Grid for Sticky Headers and Footers How to Use CSS Grid for Sticky Headers and Footers Apr 02, 2025 pm 06:29 PM

CSS Grid is a collection of properties designed to make layout easier than it’s ever been. Like anything, there&#039;s a bit of a learning curve, but Grid is

Google Fonts   Variable Fonts Google Fonts Variable Fonts Apr 09, 2025 am 10:42 AM

I see Google Fonts rolled out a new design (Tweet). Compared to the last big redesign, this feels much more iterative. I can barely tell the difference

See all articles