CSS 基础
1. 通过选择器 + 空格选择标签(选择器Selector)内的标签。
如:li h2 {
font-style: italic;
font-weight: normal;
}
2. id 选择器以 "#" 来定义,class选择器以“.”来定义。【 .class #ID】。
3. 派生选择器(表示id为sidebar的标签内的所有p标签的样式)如:
#sidebar p {
font-style: italic; text-align: right; margin-top: 0.5em; }
4. 元素(标签)+ #(表示id为sidebar且标签类型是div的元素的样式) 如:
div#sidebar{ border: 1px dotted #000; padding: 10px; }
5. 和 id 一样,class 也可被用作派生选择器(表示calss为fancy的标签内的所有td标签的样式) 如:
.fancy td {
color: #f60;
background: #666;
}
6. 元素也可以基于它们的类而被选择(表示calss为fancy的所有td标签的样式) 如:
td.fancy {
color: #f60;
background: #666;
}
如何插入样式表
1. 外部样式表 如:
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>
2. 内部样式表 如:
<head><style type="text/css">hr {color: sienna;} p {margin-left: 20px;} body {background-image: url("images/back40.gif");}</style></head>
3. 内联样式 如:
<p style="color: sienna; margin-left: 20px">
This is a paragraph
</p>

浙公网安备 33010602011771号