在网页中嵌入css的三种方法

假如有一段HTML代码如下:

1
2
3
4
5
6
7
8
<html>
<head>
<title>HI</title>
</head>
<body>
  <div id="myid" class="myclass"></div>
</body>
</html>

在HTML代码中嵌入CSS有一下三种方法:

1.外链式CSS。编写一个.css文件并且命名为style.css,内容如下:

    #myid{
     padding:5px;
    }

然后在HTML代码的《head》标签对,《title》下面改成这样:

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

这样就OK了
2.内嵌式CSS。直接在《title》标签加成这样:

   <head>
   <title>HI</title>
   <style type="text/css">
   <!--
    #myid{
     padding:5px;
     }
    -->
   </style>
   </head>

3.直接式CSS。直接为DIV添加style属性如下:

<div id="myid" class="myclass" style="padding:5px;"></div>

6 Responses to 在网页中嵌入css的三种方法 »

  1. 火星基地 评论 2008-09-27 10:25

    帮忙消灭零回复~ :idea:

    回复

    joe 回复 九月 27th, 2008 at 10:36

    :grin: 谢谢哦

    回复

  2. 最新电影 评论 2008-09-28 19:12

    学习了……

    回复

    joe 回复 九月 28th, 2008 at 19:49

    你网站不错哦,可以加链接么?

    回复

  3. welcome 评论 2008-10-27 05:46

    Неплохо конечно…

    回复

    joe 回复 十月 27th, 2008 at 08:47

    :razz: Спасибо!

    回复

Leave a Reply

Email address is not published

You should say a Chinese word to pass spam check. If you can not input Chinese, just copy 你好 and paste them into comment text box.