常見的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;}