CSS样式的三种导入方式(Three ways to import CSS Styles)

CSS样式有三种导入方式

1:行内样式表

直接在标签的style属性中书写CSS样式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1 style="color: red">Hello World</h1>
</body>
</html>

2:内部样式表

在<head>标签内的<style>标签内书写css样式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        h1{
            color:red;
        }
    </style>


</head>
<body>
    <h1>Hello World</h1>
</body>
</html>

3:外部样式表

在外部文件内书写样式,然后通过<head>标签内使用<link>标签来导入外部CSS样式文件

HTML文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/style.css">

</head>
<body>
    <h1>Hello World</h1>
</body>
</html>

CSS文件

h1{
    color: aqua;
}
————————

There are three ways to import CSS styles

1: Inline style sheet

Write CSS styles directly in the style attribute of the tag

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1 style="color: red">Hello World</h1>
</body>
</html>

2: Internal style sheet

In & lt; head> & lt; in label; style> CSS style written in label

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        h1{
            color:red;
        }
    </style>


</head>
<body>
    <h1>Hello World</h1>
</body>
</html>

3: External style sheet

Write the style in an external file, and then use & lt; head> Use & lt; link> Tag to import an external CSS style file

HTML file

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/style.css">

</head>
<body>
    <h1>Hello World</h1>
</body>
</html>

CSS file

h1{
    color: aqua;
}