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

高洛峰
Release: 2016-12-16 15:37:13
Original
2435 people have browsed it

<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!

source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!