简介
CSS指层叠样式表 (Cascading Style Sheets)。
CSS语法由两个主要的部分构成:选择器(HTML元素),以及一条或多条声明:
/*添加注释*/
selector, ...selector5 {
property: value;
...
}
p {
color: red;
text-align: center;
}
- 标签选择器:A {}
- id选择器:#name {}
- 类选择器:.name {}
- 派生选择器:A B {}
- .name A {} 或 #name A {}
- 属性选择器:[属性] {}、[属性=xxx] {}、[属性~=xxx] {}
- A>B {}
- 通用选择器:* {}
- 相邻选择器:A+B {}
- A~B {}
CSS的创建
内联样式 > 内部样式 > 外部样式 > 浏览器默认样式
外部样式:
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>
内部样式:
<head>
<style>
hr {
color: red;
}
p {
margin-left: 10px;
}
body {
background-image: url("images/xxx.gif");
}
</style>
</head>
内联样式:
<p style="color: red;margin-top: 10px">这是一个段落</p>
背景(background)
属性 | 说明 | 值 | 版本 |
---|---|---|---|
background | |||
background-attachment | |||
background-color | |||
background-image | |||
background-position | |||
background-repeat |
文本(text)
属性 | 说明 | 值 | 版本 |
---|---|---|---|
color | 颜色 | red、#ff0000、rgb(255,0,0)、inherit | CSS1 |
direction | 方向 | ltr(默认)、rtl、inherit | CSS2 |
line-height | 行高 | CSS1 | |
letter-spacing | |||
text-align | |||
text-decoration | 向文本添加修饰 | ||
text-indent | 缩进元素中文本的首行 | ||
text-shadow | |||
text-transform | |||
unicode-bidi | |||
white-space | |||
word-spacing |
字体(font)
属性 | 说明 | 值 | 版本 |
---|---|---|---|
font | |||
font-family | |||
font-size | |||
font-size-adjust | |||
font-stretch | |||
font-style | |||
font-variant | |||
font-weight | 粗细 |
链接
列表(list)
表格
轮廓(outline)
position(定位)
overflow
float(浮动)
CSS发展历程
CSS3
2005年12月,W3C开始CSS3标准的制定。