用以下三种方式将样式表加入网页:
最接近目标的样式定义优先权越高。高优先权样式将继承低优先权样式的未重叠定义但覆盖重叠的定义。
链入外部样式表文件 (Linking to a Style Sheet)先建立外部样式表文件(.css),然后使用HTML的link对象。
<head>
<title>title of article</title>
<link rel=stylesheet href="http://www.dhtmlet.com/rainer.css" type="text/css">
</head>
<title>title of article</title>
<link rel=stylesheet href="http://www.dhtmlet.com/rainer.css" type="text/css">
</head>
而在XML中应该如下例所示在声明区中加入:
<? xml-stylesheet type="text/css" href="http://www.dhtmlet.com/rainer.css" ?>
定义内部样式块对象 (Embedding a Style Block)可以在HTML文档的<HTML>和<BODY>标记之间插入<STYLE>...</STYLE>块对象。这里将style对象的type属性设置为"text/css",是允许不支持这类型的浏览器忽略样式表单。
<html>
<style type="text/css">
<style type="text/css">
<!--
body {font: 10pt "Arial"}
h1 {font: 15pt/17pt "Arial"; font-weight: bold; color: maroon}
h2 {font: 13pt/15pt "Arial"; font-weight: bold; color: blue}
p {font: 10pt/12pt "Arial"; color: black}
-->
body {font: 10pt "Arial"}
h1 {font: 15pt/17pt "Arial"; font-weight: bold; color: maroon}
h2 {font: 13pt/15pt "Arial"; font-weight: bold; color: blue}
p {font: 10pt/12pt "Arial"; color: black}
-->
</style>
<body>
<body>
内联定义 (Inline Styles) 在对象的标记内使用对象的style属性定义适用其的样式表属性。
<p style="margin-left: 0.5in; margin-right:0.5in">这一行被增加了左右的外补丁<p>
样式表语法 (CSS Syntax)
Selector { property: value }
参数说明:
Selector -- 选择符
property : value -- 样式表定义。属性和属性值之间用冒号(:)隔开。定义之间用分号(;)隔开
Selector -- 选择符
property : value -- 样式表定义。属性和属性值之间用冒号(:)隔开。定义之间用分号(;)隔开
继承的值 (The ' Inherit ' Value)
每个属性都有一个指定的值:Inherit。
它的意思是:将父对象的值等同为计算机值得到。这个值通常仅仅是备用的。显式的声明它可用来强调。