【CSS】CCS引入的三種方式

目錄

1、行內樣式

2、內部樣式表

3、外部樣式表

4、使用 @import 引用外部 CSS 文件


1、行內樣式

<p style="color:red; font-size:18px;">我的字體顏色爲紅色,大小爲18像素</p>

2、內部樣式表

<head>
    <style type="text/css">
        p 
        {
            color: red;
            font-size: 18px;
        }
    </style>
</head>

<body>
    <p>我的字體顏色是紅色,大小爲18像素。</p>
</body>

3、外部樣式表

(1)鏈接式

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

<body>
    <p>我的字體顏色是紅色,大小爲18像素</p>
</body>

(2)導入式

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

<body>
    <p>我的字體顏色是紅色,大小爲18像素</p>
</body>

※:導入式也可以用在CSS文件導入外部CSS文件,如下面的style1.css導入外部style2.css:

@import url("css/style2.css");

p
{
    color:red;
    font-size: 18px;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章