# CSS 常見選擇器功能及常用設定
CSS 簡介
---
階層式樣式表(英語:**C**ascading **S**tyle **S**heets,縮寫:CSS;又稱串樣式列表、級聯樣式表、串接樣式表、階層式樣式表)是一種用來為結構化文件(如HTML文件或XML應用)添加樣式(字型、間距和顏色等)的電腦語言。--Wikipedia
> **🌵 可以將 CSS 視為網頁的外觀"樣式"。**
選擇器功能
---
### CSS 屬性範例 :
```css=
h1{
color:blue;
font-size: 23px;
border-left: 5px solid blue;
border-bottom: 5px solid red;
}
p{
font-family: Verdana;
line-height: 1.2;
text-indent: 40px;
color: blue;
}
.wrap{
width: 100px;
margin-left: auto;
margin-right: auto;
}
.style a{
color:red;
font-weight: bold;
text-align: center;
}
.style .content{
font-weight: bold;
}
.style1{
text-align:center;
text-decoration: line-through;
letter-spacing: 5px;
color: aqua;
}
.style2{
color: brown;
line-height: 30px;
}
.btn{
color:white;
background:gray;
display:block;
width: 100px;
height: 40px;
}
.box{
margin-left: 30px;
border: 5px solid blue;
width: 600px;
padding: 30px;
}
.box p{
margin-bottom: 50px;
}
a{
color: chartreuse;
}
a:hover{
color: blueviolet;
font-size: 25px;
}
a:active{
color:coral;
font-size: 20px;
}
span{
color:red;
font-size: 30px;
}
img{
border: 5px dashed #000;
}
```
### 選擇器功能 :
* **標籤選擇器**
- **h1 ,p , a, span, img** . . .
* **擬態選擇器**
- **hover** : 游標徘徊於上時的屬性
- **active** : 點按不放時的屬性
* **類別選擇器**
- **.自訂名稱** : 自訂名稱屬性 (小數點+自訂樣式名稱 於html 使用class指定)
* **後代選擇器**
- **.自訂名稱(標籤)** : 如 `.style a` 為div裡設class為style的a標籤
### 常用設定 :
* **margin** : 外推邊界 (*不會增加html元素長寬) ,可使用左右auto來置中內容
* **border** : 邊框線 (會增加html元素長寬)
* **padding** : 內推留白 (會增加html元素長寬)
* **text-align** : 文字對齊(左.中.右)
### CSS 設定 :
* **Reset** : 清空瀏覽器預設樣式 (加入在原CSS上方)
```css=
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
```
* **全部html標籤都使用固定box尺寸** : border會向內扣,不會增加尺寸
```css=
*,*:before,*:after{
box-sizing: border-box;
}
```