摘自:http://blog.163.com/dingchunkun_2006@126/blog/static/17149215120113223546835/
在HTML中引入CC有好几种方法,按优先级排列分别是:1、行内式,2、嵌入式,3、导入式和链接式
在HTML中引入CSS的方法有以下几种:
1)行内式
比如:
<body>
<h1 style="color:white;background-color:blue">
This is a line of Text.
</h1>
</body>
2)嵌入式
比如:
<head>
<style type="text/css">
h1{
color:white;
background-color:blue
}
</style>
</head>
<body>
<h1>This is a line of Text.</h1>
<h1>This is another line of Text.</h1>
</body>
3)导入式和链接式
先要把CSS的内容写到一个.CSS的文件中
比如:mycss.css
h1{
color:white;background-color:blue
}
导入式写法(注意CSS文件的路径要正确):
<head>
<style type="text/css">
@import"mycss.css";
</style>
</head>
<body>
<h1>This is a line of Text.</h1>
<h1>This is another line of Text.</h1>
</body>
链接式写法(注意CSS文件的路径要正确):
<head>
<link href="mycss.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<h1>This is a line of Text.</h1>
<h1>This is another line of Text.</h1>
</body>
本文介绍了在HTML中引入CSS的三种主要方式:行内式、嵌入式以及导入式和链接式。行内式直接在HTML元素中设置样式;嵌入式将CSS代码放在HTML头部的<style>标签内;导入式和链接式则通过引用外部CSS文件实现。

518

被折叠的 条评论
为什么被折叠?



