CSS基础知识
1、CSS的语法是这样的:selector {property: value}
selector-选择器(比如body、div、h2……)
property-属性 (比如background-color、hidden、text-align……)
value-值(比如yellow、blue、12px、center……)
[注]:
a、除id外大小写不敏感
b、value存在多个单词时,要用引号(比如:font-family: "Book Antiqua";)
c、设置完一项后,以;结尾
2、下面是一个CSS文件的示例:
@CHARSET "UTF-8";
/*可以为多个html元素或标签定义样式*/
h1,h2 {
color: aqua;
}
/*为单个元素或标签定义样式*/
h3 {
font-style: italic;
}
h4 {
color: silver;
}
table {
color: blue;
}
/*为table中的label定义样式*/
table label {
color: purple;
}
/*为id为redDiv的元素或标签定义样式*/
#redDiv {
color: red;
}
/*为id为redDiv的元素或标签中的h3标签定义样式*/
#redDiv h3 {
color: green;
}
/*为class为bg的元素或标签定义样式*/
.bg {
background-color: yellow;
}
/*为class为bg的元素或标签中的p标签定义样式*/
.bg p {
background-color: silver;
}
我们看到,可以通过
a、 XX{******}为某一元素或标签定义样式
b、 XX,YY{******}为多个元素或标签定义样式
c、 XX YY{******}为XX元素(或标签)中的YY元素(或标签)定义样式
d、 #XX{******}为id为XX的元素或标签定义样式
e、 #XX YY{******}为id为XX的元素(或标签)中的YY元素(或标签)定义样式
f、 .XX{******}为使用了XX类的元素或标签定义样式(class="XX")
g、 .XX YY{******}为使用了XX类的元素(或标签)中的YY元素(或标签)定义样式
3、html页面
我们可以将CSS样式规则写在html页面里(head标签之间)
<head>CSS here</head>
也可以导入外部的CSS样式文件(也是head之间)
<link rel="stylesheet" type="text/css" href="test.css" />
4、下面是一个引入了上面CSS文件的html页面:
<html>
<head>
<title>css test</title>
<!-- 引入外部样式表(也可以将CSS写在页面里) -->
<link rel="stylesheet" type="text/css" href="test.css" mce_href="test.css" />
</head>
<body>
<h1>这是h1(aqua)</h1>
<h2>这是h2(aqua)</h2>
<!-- 受到h4样式规则和class bg
相关文档:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<TITLE>无刷新变换样式表</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /& ......
1.position的absolute属性表示该块已经完全脱离文本流了。也就是不再占用空间位置
。完全靠top,button,right,left来进行定位。
这个必须能够完全理解。同时为减少错误在设置absolute后,一定至少指定top,buttom,right,left中的一个。
2.如果块设置了absolute属性,其定位的原点和父块的position有关。
如果父块设置 ......
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> &nb ......
1. 定义样式
1.1 按html标签定义
例如:body{background-color:#999999; text-align:center}
1.2 按类定义
例如:.style1{border-style:solid; border-color:#0000FF; border-width:1px}
1.3 按id定义
例如:#style2{border-style:solid; border-color:#FF0000; border-width:1px}
2. CSS的位置和引用
......