Home > Web Front-end > Front-end Q&A > How to call css files in HTML

How to call css files in HTML

青灯夜游
Release: 2021-04-26 12:02:40
Original
4452 people have browsed it

Calling method: 1. In the head part of the document, use the statement ""; 2. In the style Within the tag, use the "@import url("file path")" statement to call.

How to call css files in HTML

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

There are three ways to introduce CSS styles: inline styles, internal style sheets, and external style sheets. Among them, the external style sheet is a .css file containing css styles.

So how to call external css files in HTML? There are two methods: link type and import type.

Grammar:

1. Link type

<link type="text/css" rel="styleSheet"  href="CSS文件路径" />
Copy after login

2. Import type

<style type="text/css">
  @import url("css文件路径");
</style>
Copy after login

For example:

<!DOCTYPE>
<html>
<head>
  <meta charset="utf-8" />
  <title>外部样式表</title>
  <!--链接式:推荐使用-->
  <link rel="stylesheet" type="text/css" href="css/style.css" /> 
  <!--导入式-->
  <style type="text/css">
    @import url("css/style.css");
  </style>
</head>
<body>
     <ol>
         <li>1111</li>
         <li>2222</li>
     </ol>
</html>
Copy after login

The difference between link type and import type

1. Belongs to XHTML

2. Loading first CSS file to the page

@import

1. It belongs to CSS2.1

2. Load the HTML structure first and then load the CSS file.

(Learning video sharing: css video tutorial)

The above is the detailed content of How to call css files in HTML. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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