1. 程式人生 > >css 偽類

css 偽類

auto 技術 元素 lin div bsp htm har pos

a標簽 必須按順序寫

link 鏈接未訪問的時候的樣式

visited 鏈接訪問後的樣式

hover 鼠標放上去的樣式

active 鏈接在訪問時的樣式

after

before

nth-of-type(2n)  選擇屬於其父級下面第n個元素
隔行換色:
技術分享圖片
 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Title</
title> 6 <style> 7 p:nth-of-type(2n){ 8 background: red; 9 } 10 p:nth-of-type(2n-1){ 11 background-color: gold; 12 } 13 </style> 14 </head> 15 <body> 16 <p>1</p> 17 <p>2</p> 18 <
p>3</p> 19 <p>4</p> 20 <p>5</p> 21 <p>6</p> 22 </body> 23 </html>
View Code 技術分享圖片
 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Title</title>
 6     <style>
7 div{ 8 width: 980px; 9 margin: 0 auto; 10 overflow: auto; 11 } 12 span{ 13 float: left; 14 width: 300px; 15 height: 300px; 16 background-color: red; 17 margin:10px ; 18 } 19 span:nth-of-type(3n-1){ 20 margin-left: 10px; 21 margin-right: 10px; 22 } 23 </style> 24 </head> 25 <body> 26 <div> 27 <span>1</span> 28 <span>2</span> 29 <span>3</span> 30 <span>4</span> 31 <span>5</span> 32 <span>6</span> 33 <span>7</span> 34 <span>8</span> 35 <span>9</span> 36 <span>10</span> 37 <span>11</span> 38 <span>12</span> 39 </div> 40 </body> 41 </html>
View Code

css 偽類