HTML样式CSS的三种写法

html-css023

HTML样式CSS的三种写法,第1张

CSS是样式层叠表,有三种引入方式。下面,我们来看看HTML样式CSS的三种写法吧。

行内样式

CSS可以直接放到行内样式中引入即可,比如代码如下图:

<p style="color: bluebackground: red">

hello world!

</p>

嵌入式

还可以采用潜入方式引入CSS,就是把CSS写到<style>标签中,这种方式比较实用,如下图所示:

<style type="text/css">

h1 {color: red}

</style>

<h1>helloworld</h1>

外部样式表

还有一种叫做外部样式,也就是把CSS写在另外一张页面上,然后再引用到指定页面就可以了,这种也很常见。

@import url(main.css)

<html>

<head>

<style type="text/css">

a.top:link {font-family: 宋体} /*链接字体*/

a.top:link {font-weight: normal} /*设置链接文字中的字符粗细*/

a.top:link {font-size: 12} /*设置链接文字的大小*/

a.top:link {text-decoration: none} /*设置链接文字没有下划线*/

a.top:hover {text-decoration: underline} /*鼠标放在链接上时有下划线*/

a.top:link {color: #000000} /*设置链接文字的颜色*/

a.top:visited {color: #000000} /*访问过的链接*/

a.top:hover {color: #B50000} /*鼠标放在链接上字体的颜色*/

a.tj:link {font-family: 宋体}

a.tj:link {font-weight: normal}

a.tj:link {font-size: 12}

a.tj:link {text-decoration: none}

a.tj:hover {text-decoration: none}

a.tj:link {color: #000000}

a.tj:visited {color: #0000ff}

a.tj:hover {background: #FFFFCC}

h1 {font-size:12px} 

h1 {font-family: "宋体"} 

h1 {font-weight: normal}

h1 {color: #000000}

h2 {font-size:14px} 

h2 {font-family: "宋体"} 

h2 {font-weight: normal}

h2 {color: #000000}

h3 {font-size:24px} 

h3 {font-weight: 1}

h3 {color: #000000}

body {

        margin-top: 1px /*上边距*/

        margin-bottom: 1px /*下边距*/

}

</style>

<meta http-equiv="Content-Type" content="text/html charset=gb2312"></head>

<body>

<p>Mouse over the links to see them change layout.</p>

<p><b><a href="default.asp" target="_blank" class="top">电脑对怀孕其实没啥影响</a></b></p>

<p><b><a href="default.asp" target="_blank" class="tj">电脑对怀孕其实没啥影响</a></b></p>

<h1>电脑对怀孕其实没啥影响</h1>

<h2>电脑对怀孕其实没啥影响</h2>

<h3>电脑对怀孕其实没啥影响</h3>

</body>

</html>