设计一段html和css代码,其中至少包含三个div,分别展示三种css+引入方式?

如题所述

第1个回答  2022-12-08

html: 

<!DOCTYPE html>

<html>

<head>

<title>My webpage</title>

</head>

<body>

<div>

<h1>My first div</h1>

<p>This div uses inline CSS to style its content.</p>

<style>

h1 {

color: red;

}

p {

font-size: 16px;

text-align: center;

}

</style>

</div>

<div>

<h1>My second div</h1>

<p>This div uses an external CSS file to style its content.</p>

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

</div>

<div>

<h1>My third div</h1>

<p>This div uses an embedded style sheet to style its content.</p>

<style>

/* This is an embedded style sheet */

h1 {

color: blue;

}

p {

font-size: 14px;

text-align: left;

}

</style>

</div>

</body>

</html>


style.css:

/* This is an external style sheet */

h1 {

color: green;

}

p {

font-size: 18px;

text-align: right;

}


这段代码中,第一个div使用内联CSS来样式其内容,第二个div使用外部CSS文件来样式其内容,第三个div使用嵌入式样式表来样式其内容。

相似回答
大家正在搜