---
title: "重学 CSS"
author: "Kyll"
date: "2007-12-04T14:41:13Z"
tags: ["CSS", "Firefox", "IE", "工作", "浏览器"]
slug: "css"
draft: false
lastmod: "2007-12-04T14:41:13Z"
id: 145870
url: "https://kyll.iteye.com/blog/145870"
---

原文出自 www.w3schools.com 中的 CSS 教程。 注意： 样式名称不要以数字开始， Mozilla/Firefox 无法工作。 注释： /* ... \*/ 属性值和单位之间不要有空格。 20px不能写成 20 px 样式的顺序： 浏览器默认 &lt; 外部样式 &lt; 内部样式 &lt; 内联样式 CSS 语法： selector {property: value} 例： body {color: black} p {font-family: "sans serif"} 组： h1,h2,h3,h4,h5,h6 {color: green} 类选择器： p.right {text-align: right} p.center {text-align: center} 例：

This paragraph will be right-aligned.

This paragraph will be center-aligned.

引用多于一个的样式： center 与 bold 分别是两个样式的名字。

This is a paragraph.

不带标签名称的选择器， 任何标签都可用： .center {text-align: center}

# This heading will be center-aligned

This paragraph will also be center-aligned.

匹配所有 input 元素中 type 属性为 text 的： input\[type="text"] {background-color: blue} ID 选择器： 以 # 开始， 匹配 ID 为 green 的元素 #green {color: green} 匹配

元素中 ID 为 para1 的元素 p#para1 { text-align: center; color: red } 引用外部样式： 内部样式： 要有 HTML 注释 内联样式：

This is a paragraph

样式覆盖： 样式1： h3 { color: red; text-align: left; font-size: 8pt } 样式2： h3 { text-align: right; font-size: 20pt } 最后： h3 { color: red; text-align: right; font-size: 20pt } a:link {color: #FF0000} /* unvisited link \*/ a:visited {color: #00FF00} /* visited link \*/ a:hover {color: #FF00FF} /* mouse over link \*/ a:active {color: #0000FF} /* selected link \*/ 匹配

中的第一个

div &gt; p:first-child { text-indent:25px } 匹配

中的第一个 *p:first-child em { font-weight:bold } p:first-line {color:#0000ff;font-variant:small-caps} p:first-letter {color:#ff0000;font-size:xx-large} h1:before { content: url(beep.wav) } h1:after { content: url(beep.wav) } 图像透明： ![klematis](klematis.jpg) Mozilla： -moz-opacity:x x值（0.0 - 1.0） IE： filter:alpha(opacity=x) x值（0 - 100）*