您的位置:首页 > Web前端 > CSS

css学习

2016-04-13 20:19 471 查看
博客来源:http://lib.csdn.net/base/18/structure ---非常好的学习js,css的网站

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

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

如:颜色

p { color: [code]#ff0000
; } 缩写为:p { color:
#f00
; }[/code]

p { color: [code]rgb(255,0,0)
; }
p { color:
rgb(100%,0%,0%)
; }[/code]
对选择器分组,使他们共享属性

h1,h2,h3,h4,h5,h6
{
color: green;
}[/code]
子元素可以从父元素继承属性

派生选择器:

id
选择器以 "#" 来定义

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


一个选择器,多种用法

即使被标注为 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;
}[/code]
类选择器以一个点号显示:

.center
{text-align: center}[/code]

和 id 一样,class 也可被用作派生选择器:
.fancy td
{
color: #f60;
background: #666;
}[/code]
熟悉选择器和值选择器


属性选择器

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

{
color:red;
}[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: