常见的html标签元素css
h1 { color: red; } body { background: red; }
例如body和h2标签的字体颜色都是red,使用逗号将其隔开。html
body, h1 { color: red; }
* { color: red; }
在html标签中使用class属性,而后使用样式属性。字体
<a class="customClassName1'>hello,world</a>
<a class="customClassName2'>hello,world</a>
<a class="nameOne nameTwo">hello,world</a>
样式表:this
.customClassName1 { color: red; background: blue; }
a.customClassName2 {
font-weight: bold;
}
.nameOne.nameTwo {
background: silver;
}
//不能匹配到,没有nameThree
.nameOne.nameThree {
font-weight: bold;
}
id选择器前面使用#。id是html元素惟一标识符spa
<a id="customId">hello, use id selector</a>
css文件htm
#customId { font-size: 12px; }
经过标签属性来设置样式。两种方式:blog
1.具体属性名称的值,属性值须要全值匹配:标签名[属性名=‘属性值’] 文档
2.属性名称: 标签名[属性名]get
<a name="attrName">hello, world</a>
<a name="attrName2">hello, world</a>
css样式:it
a[name] { background: red; }
a[name="atriName2"] {
background: red;
}
html是文档结构模型的,都有父子节点。能够经过节点关系进行选择。
<div> <h1>1</h1> <span>
<b>2</b>
</span> </div>
css编写:
div h1 { color: red; } div span b { color: blue; }
<div> <h1>this is first h1</h1> <h2>this is second h2</h2> </div>
子元素css
div > h1 { font-weight: bold; }
<div> <h1 class="target">1</h1> <h2 class="getTarget">2</h2> <div>
css:
.target + .getTarget { color: red; }
a连接相关的伪类有5个:
a.静态伪类: :link , :visited
b.动态伪类 : :focus, :hover , :active
使用顺序通常为: link - visited - focus- hover - active
<div> <h1>first </h1> <h2>second</h2> <div>
css:
div:first-child { color: red; }
<p>first line</p>
<p>first letter</p>
css:
//a. 设置首字母样式p:first-letter { font-size: 20px; }//b.设置首行p:first-line { color: purple;}