css学习

来源:互联网 发布:投资数据库终端 编辑:程序博客网 时间:2024/06/02 05:40

博客来源:http://lib.csdn.net/base/18/structure  ---非常好的学习js,css的网站

css规则:选择器和声明,选择器通常是你需要改变的html元素;每条声明由一个属性和值组成,

即: 选择器:{属性:值; 属性:值......}

如:颜色

p { color: #ff0000; }  缩写为:
p { color: #f00; }

p { color: rgb(255,0,0); }p { color: rgb(100%,0%,0%); }
对选择器分组,使他们共享属性
h1,h2,h3,h4,h5,h6 {  color: green;  }
子元素可以从父元素继承属性

派生选择器:

id 选择器以 "#" 来定义

#red {color:red;}#green {color:green;}
<p id="red">这个段落是红色。</p><p id="green">这个段落是绿色。</p>

一个选择器,多种用法

即使被标注为 sidebar 的元素只能在文档中出现一次,这个 id 选择器作为派生选择器也可以被使用很多次:

#sidebar p {font-style: italic;text-align: right;margin-top: 0.5em;}#sidebar h2 {font-size: 1em;font-weight: normal;font-style: italic;margin: 0;line-height: 1.5;text-align: right;}
类选择器以一个点号显示:

.center {text-align: center}

和 id 一样,class 也可被用作派生选择器:

.fancy td {color: #f60;background: #666;}
熟悉选择器和值选择器

属性选择器

下面的例子为带有 title 属性的所有元素设置样式:

[title]{color:red;}

0 0
原创粉丝点击