CSS樣式在HTML中引入

2021-08-19 21:17:55 字數 2254 閱讀 8555

-------------------------------------css樣式在html中引入---------------------------------------------

第一種方式在html的頭資訊中定義css

**示例:

doctype

html>

<

html

>

<

head

>

<

meta

charset

="utf-8"

>

<

title

>

insert title here

title

>

<

style

type

="text/css"

>

/* 

我是css

注釋*/

p

style

>

head

>

<

body

>

<

p>

www.likunpeng.com

p>

<

p>

李昆鵬p

>

<

p>

cssp

>

body

>

html

>

第二種引入方式

通過head標籤中link標籤來實現,前提也是先要有乙個已定好的css檔案。

注:可以通過多個link標籤鏈結進來多個css檔案。重複樣式以最後鏈結進來的css樣式為準。

**示例:

首先建立css檔案

@charset

"utf-8"

;p

--------------------------------------

再將css檔案引入到html頭中

doctype

html>

<

html

>

<

head

>

<

meta

charset

="utf-8"

>

<

title

>

insert title here

title

>

<

link

href

="style.css"

type

="text/css"

rel="stylesheet"

>

head

>

<

body

>

<

p>

www.likunpeng.com

p>

<

p>

李昆鵬p

>

<

p>

cssp

>

body

>

html

>

還有一種方式將css檔案引入到html頭中 

doctype

html>

<

html

>

<

head

>

<

meta

charset

="utf-8"

>

<

title

>

insert title here

title

>

<

style

type

="text/css"

>

@import

url("style.css");

style

>

head

>

<

body

>

<

p>

www.likunpeng.com

p>

<

p>

李昆鵬p

>

<

p>

cssp

>

body

>

html

>

html中引入css樣式

每個元素都有style屬性,格式 元素 style 屬性名 屬性值 內容 行內樣式表的屬性不需要雙引號,屬性值得單位通常是畫素px為單位 在中新增style,在當前的文件可以使用該樣式,需要的時候可以使用 新建乙個擴充套件名為.css的檔案,新增選擇器及其屬性,如 p在需要引入該檔案中的屬性的檔案 ...

CSS3 在HTML中引入CSS樣式

html code style color tomato 微微一笑很傾城h1 style font size 32px color tomato 微微一笑很傾城p 這種方式不能使內容與樣式相分離,本質上沒有體現出css的優勢,因此不推薦使用。html code charset utf 8 內部樣式表...

在HTML中引入CSS的方式

有 4 種方式可以在 html 中引入 css。其中有 2 種方式是在 html 檔案中直接新增 css 另外兩種是引入 外部 css 檔案。內聯方式 內聯方式指的是直接在 html 標籤中的 style 屬性中新增 css。嵌入方式 嵌入方式指的是在 html 頭部中的 標籤下書寫 css 鏈結方...