CSS 標籤整理
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
基本HTML範例
CSS 基本語法
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Selector(選擇器) - 通常是元素、類別或ID
Declaration(宣告) - 由Property(屬性)和Value(值)所組成,宣告間以分號區隔,最外圍用大括號括住。
CSS 套用方法
- 行內載入
寫在元素標籤後面,原始的寫法,較不易更改和維護
- 內部載入
格式放在<head>
的<style>
中,設定相對應選擇器的格式,可同時做新增、修改
- 外部載入
將CSS格式獨立寫成*.css檔,從HTML內部載入外部的檔案即可,寫法是在<head>
使用<link>
,或是在<style>
中使用@import載入外部檔案
CSS 各類選擇器
- 類別選擇器
可多重繼承
- ID選擇器
只能單一繼承
- 標籤選擇器
可指定標籤名稱,所有相同標籤名稱都會套用此格式
- 群組選擇器
可將多個指定的選擇器套用相同的格式
-
屬性選擇器
可指定屬性套用相同的格式,有多種寫法
- 標籤[屬性]
選擇標籤元素指定的屬性
- 標籤[屬性 = "值"]
選擇標籤元素指定的屬性和值(需一模一樣)
- 標籤[屬性 ~= "值"]
選擇標籤元素指定的屬性包含值的設定,設定包含值使用空格隔開單字,只要一個單字符合,即套用相同格式
- 標籤[屬性 |= "值"]
選擇標籤元素的屬性值是開頭文字加上-符號
- 標籤[屬性 ^= "值"]
選擇標籤元素的指定屬性,其值符合開頭文字
- 標籤[屬性 $= "值"]
選擇標籤元素的指定屬性,其值符合結尾文字
- 標籤[屬性 *= "值"]
選擇標籤元素的指定屬性,其值符合任何一處文字
-
後代選擇器
指定父標籤下的所有子標籤套用CSS格式
- 子選擇器
和後代選擇器差不多,只差在層級須完全相同
CSS 虛構類別
a:link
未照訪的網站
a:visited
照訪過的網站
選擇器:hover
游標觸碰到的狀態
選擇器:active
點擊時的狀態
選擇器:focus
按下元件後的狀態
選擇器:enable
啟用元件的狀態,通常是input元件
選擇器:disable
未啟用元件的狀態,通常是input元件
選擇器:first-child
該選擇器中第一個出現的
選擇器:last-child
該選擇器中最後一個出現的
選擇器:n-child(odd)
選擇器中的奇數個出現的
選擇器:n-child(odd)
選擇器中的偶數個出現的
CSS 虛構元素
選擇器::first-line
選擇器中第一行的狀態
選擇器::first-letter
選擇器中第一行第一個字母的狀態
選擇器::before
選擇器緊臨前方位置的狀態
選擇器::after
選擇器緊臨後方位置的狀態
選擇器::selection
反白部分的狀態
CSS 顏色
範例 : CSS08.htm
漸層
-
background:radial-gradient(形狀/大小/指定位置,色彩停止點1,色彩停止點2,...,色彩停止點n)
放射漸層
- 形狀,如circle、ellipse
- 距離,度量單位,代表從中心點向外的半徑
- 指定位置,如 at + top、bottom、left、right
- 色彩停止點,色彩後空一格加上百分比或度量單位
圓黑外漸
圓黑20像素
圓心在上
-
background:linear-gradient(方向,色彩停止點1,色彩停止點2,...,色彩停止點n)
線性漸層
- 方向,如0deg、90deg
- 指定位置,如 to + top、bottom、left、right
標題常用
由下而上
由左而右
彩虹
-
background:repeating-radial-gradient(屬性值)
重複漸層
background:repeating-linear-gradient(屬性值)
重複
圓型重複
上下間隔
CSS 文字
-
font-size:值
改變字體大小
- px 像素點
- cm 公分
- mm 公釐
- em 上層元素的相對大小
- xx-small、x-small、small、medium、large、x-large、xx-large 預設大小
- 200% 相對大小
-
font-family:字型1,字型2,...
改變文字字型
靠左優先,無法顯示時則顯示新細明體
-
font-style:值
斜體字
-
font-weight:值
改變文字粗細
- 數值,100~900數字越大越粗
- lighter、normal、bold、bolder,預設值
-
font:斜體字 文字粗細 字體大小 文字字型
設定font簡便寫法
-
text-decoration:值
裝飾線
- underline 底線
- overline 頂線
- line-through 刪除線
-
text-transform:值
英文大小寫轉換
- uppercase 全部大寫
- lowercase 全部小寫
- capitalize 字首大寫
-
line-height:值
行高
-
text-indent:值
首行縮排
-
word-spacing:值
文字間距
-
letter-spacing:值
字母間距
-
text-shadow:水平移動量 垂直移動量 模糊值 色彩
可設定雙重陰影,兩者間用,符號隔開
-
box-shadow:水平移動量 垂直移動量 模糊程度 色彩
可設定雙重陰影,與text-shadow相似
-
text-stroke:粗細 顏色
文字外框線
NEW YORK
-
text-align:值
文字對齊方式
- center 置中
- left 靠左
- right 靠右
-
vertical-align:值
文字垂直對齊方式
- top 對齊顯示區域上緣
- text-top 對其前標籤上緣
- bottom 對齊顯示區域下緣
- text-bottom 對其前標籤下緣
- middle 對其前標籤中緣
CSS 清單項目
CSS 背景
-
background-color:顏色值
設定背景顏色
設定背景顏色
-
background-image:url(圖片檔案路徑)
設定背景圖片
-
background-repeat:屬性值
背景圖片重複設定
- no-repeat 不重複顯示
- repeat-x X軸方向重複
- repeat-y X軸方向重複
- repeat X軸和Y軸方向重複
- space 重複且圖片完整與自動調節間距
- round 重複且圖片完整與自動調節間距(和space差不多)
-
background-position:X座標 Y座標
設定背景圖片位置
- X座標
- left 靠左
- center 置中
- right 靠右
- Y座標`
- top 置頂
- center 置中
- bottom 置底
-
background-origin:原點位置
設定原點位置
- padding-box 以內距的左上角為原點,預設值
- border-box 以框線的左上角為原點
- content+box 以內容的左上角為原點
-
background-clip:裁切位置
設定背景裁切方式
- border-box 將框線以外的部分去除,預設值
- padding-box 將內距以外的部分去除
- content-box 將內容以外的部分去除
-
background-attachment:屬性值
設定背景圖片捲動跟隨
補充 - 浮動廣告
讓廣告可以跟著畫面移動,點擊即可進入連結
background-size:屬性值
設定背景圖片大小
- 度量單位
- 百分比
- contain 符合區塊大小
- cover 覆蓋區塊大小
- auto
CSS 版面定位
box model

CSS 框線設定
CSS 外框線設定
-
outline-style:屬性值
設定外框線樣式
-
outline-width:屬性值
設定外框線寬度
-
outline-color:顏色
設定外框線顏色
與border相同屬性值,參照"CSS 框線設定"
-
outline:樣式 寬度 顏色
外框線簡便寫法
不可針對單邊進行設定
-
outline-offset:數字
設定框線和外框線的間距
CSS 表格框線
-
border-collapse:屬性值
表格框線分離/不分離
-
border-spacing:屬性值
表格框線距離
-
table-layout:屬性值
設定版面編排
-
empty-cells:屬性值
設定空白儲存格顯示/影藏
-
caption-side:屬性值
表格標題位置
CSS Flex
祕訣一: 要讓內元件有效果,要在外元件加上 display:flex
祕訣二: 每個 HTML 標籤,能同時擁有內元件跟外容器身份
Flex 主軸與交錯軸觀念(測試工具)
-
flex-direction
: 決定軸線
- row : 水平
- row-reverse : 水平,但順序相反
- column : 垂直
- column-reverse : 垂直,但順序相反
-
justify-content
: 主軸對齊
- flex-start : 對齊靠左
- center : 對齊置中
- flex-end : 對齊置左
- space-between : 平均分散
- space-around
- space-evenly
-
flex-wrap
: 換行屬性
-
align-item
: 交錯軸對齊(垂直置中)
- flex-start
- center
- flex-end
- stretch
- baseline
參考
體驗營第二週講義
Flex 補充資源
CSS 變形效果
範例 : CSS15.htm
對照組
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
scale(x位移量,y位移量)
縮放
scaleX(x位移量)
scaleY(y位移量)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
skew(x位移量,y位移量)
傾斜
skewX(x位移量)
skewY(y位移量)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
CSS 2D轉場效果
範例 : CSS17.htm
transition-duration:秒數
轉場時間
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
transition:轉場時間 轉場屬性 轉場模式 轉場延遲
CSS 動畫效果
-
@keyframes
動畫關鍵影格
-
animation-name:關鍵影格名稱
動畫名稱設定
-
animation-duration:秒數
動畫持續時間
-
animation-time-function:屬性值
動畫轉換模式
-
animation-iteration-count:重複次數
重複次數設定
- 數字,代表動畫重複的次數,如
animation-iteration-count:2
代表重複2次
- infinite,無限次數播放,永遠不會停
-
animation-direction:播放方向
播放方向設定
- normal 代表從動畫開頭到結束,預設值
- reverse 代表從動畫結束倒帶回開頭,和normal相反效果
- alternate 從動畫開頭到結束,再從動畫結束倒帶回開頭。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
注意,開頭到結束算第1次播放,結束倒帶回開頭算第2次播放,所以設定播放次數必須大於1次,才能正常顯示效果
- alternate-reverse 動畫結束倒帶回開頭,再從動畫開頭到結束,與alternate相反效果
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
animation-delay:秒數
播放延遲設定
animation-play-state:播放狀態
播放狀態設定
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
animation:影格名稱 動畫時間 轉換效果 重複次數 播放次數 延遲時間 播放狀態
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
RWD 響應式網站
格式
@media 裝置 and (裝置屬性: 值)
例子:@media screen and (min-width: 900px)
-
@media 媒體
不同裝置
- all 預設值,全部
- screen PC、手機瀏覽器都是
- print 印表機
-
min-width
求最大寬度
max-width
求最小寬度
-
min-height
求最大高度
max-height
求最小高度
-
min-device-width
求最大螢幕寬度
max-device-width
求最小螢幕寬度
-
min-device-height
求最大螢幕高度
max-device-height
求最小螢幕高度
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
響應式網站常用,放在<head>
中
CSS 進階補充
NEW YORK
NEW YORK
-
font-variant:字體
轉換特殊字體
- normal 預設值
- small-caps 以大寫小字顯示小寫
Small Caps
-
font-size-adjust:長寬比
自動調整文字大小
-
text-emphasis:樣式 填滿 顏色
強調標記
text-emphasis-position:顯示位置
強調標記的顯示位置
- 樣式,dot、circle、double-circle、triangle等等
- 填滿,filled、open
- 顏色
- 顯示位置,如over、under
紐約是美國第一大城
紐約是美國第一大城
-
writing-mode:直書或橫書
指定直書或橫書
- horizontal-tb 橫書,預設值
- vertical-rl 直書,欄從右到左排列
- vertical-lr 直書,欄從左到右排列
-
z-index:屬性值
設定圖層順序
- auto 和上層元素相同,預設值
- 數字 數字大的會擋住數字小的元素,如1>(-1),1就會擋住(-1)
- 詳細
-
cursor:游標形狀
設定游標形狀
- auto 預設值
- all-scroll
- grab
- none
- not-allowed
- pointer
- progress
- wait
- 更多
-
CSS 導航欄
垂直導航欄
範例 : CSSad01.htm
水平導航欄
範例 : CSSad02.htm
詳細
文字
範例 : CSSad03.htm
按鈕
範例 : CSSad04.htm
圖片
範例 : CSSad05.htm
詳細
範例 : CSSad06.htm
- CSS 3D轉場效果
rotateX()
以X軸為軸心做旋轉
rotateY()
以Y軸為軸心做旋轉
rotateZ()
以Z軸為軸心做旋轉
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →