DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> CSS入門知識 >> CSS特效代碼
CSS3 動態過渡與圖形變換大全
編輯:CSS特效代碼     
撰寫 CSS3 屬性時,最好加上瀏覽器內核標識以確保相容:
-ms-transform: scale(2,4); /* IE 9 */
-moz-transform: scale(2,4); /* Firefox */
-webkit-transform: scale(2,4); /* Safari and Chrome */
-o-transform: scale(2,4); /* Opera */

1. 圓角(常用,略)

2. 邊框陰影

box-shadow 屬性可為元素添加一個或多個陰影:

box-shadow: h-shadow v-shadow blur spread color inset;

h-shadow(必需)水平陰影位置,允許負值;v-shadow(必需)垂直陰影位置,允許負值;blur(可選)模糊距離;spread(可選)陰影尺寸;color(可選)陰影顏色;inset(可選)將外部陰影改為內部陰影。

範例:

div { box-shadow: 10px 10px 5px 5px #888888; }

3. 邊框圖片

border-image 是簡寫屬性,包含:border-image-source(邊框圖片的路徑)、border-image-slice(圖片邊框向內偏移)、border-image-width(圖片邊框寬度)、border-image-outset(邊框圖像區域超出邊框的量)、border-image-repeat(是否平鋪、鋪滿或拉伸)。

4. 設定背景繪製區域 background-clip

background-clip: border-box | padding-box | content-box;

div { background-color: yellow; background-clip: content-box; }

div { background-color: yellow; background-clip: padding-box; }

div { background-color: yellow; background-clip: border-box; }

5. 設定背景圖尺寸 background-size

CSS3 之前,背景圖尺寸由圖片實際尺寸決定;CSS3 起可自訂尺寸,方便在不同環境重複使用同一張背景圖:

background-size: length | percentage | cover | contain;

length 設定高度與寬度(第一個值為寬、第二個為高):

div { background: url(img_flwr.gif); background-size: 80px 60px; background-repeat: no-repeat; }

6. CSS3 字體 @font-face

在新版 @font-face 規則中,必須先定義字型名稱(如 myFirstFont),再指向該字型檔,然後透過 font-family 引用:

<style>
@font-face {
font-family: myFirstFont;
src: url('Sansation_Light.ttf'), url('Sansation_Light.eot'); /* IE9+ */
}
div { font-family: myFirstFont; }
</style>

7. 2D 轉換 transform

translate() 改變元素位置;rotate() 旋轉元素;scale() 放大縮小;skew() 元素傾斜;matrix() 矩陣變換。transform 允許對元素進行旋轉、縮放、移動或傾斜。

8. 過渡 transition

CSS3 過渡是元素從一種樣式逐漸過渡到另一種的效果,需指定兩項:要添加效果的 CSS 屬性、效果時長。

例一:滑鼠移入 div,寬度緩慢變化,移開後還原。

div { width:100px; height:100px; transition: width 2s; } 
div:hover { width:300px; }

例二:滑鼠移入 div,緩慢移動到另一位置。

div { width:100px; height:100px; background:yellow; transition: margin-left 2s; } 
div:hover { margin-left:300px; }

例三:結合兩個效果。

div { width:100px; height:100px; background:yellow; transition: margin-left 2s, width 1s; /* 多個屬性用逗號分隔 */ } 
div:hover { margin-left:300px; width:300px; }

例四:transition 是簡寫,包含 transition-property(套用過渡的屬性名)、transition-duration(過渡時間,預設 0)、transition-timing-function(時間曲線,預設 ease,另有 linear、ease-in、ease-out、ease-in-out、cubic-bezier 等)、transition-delay(何時開始,預設 0)。

9. 2D 轉換與過渡的結合

例一:與 rotate 結合,在原位置旋轉。

div { margin:30px; width:200px; height:100px; background-color:yellow; transition: transform 2s; } 
div:hover { transform: rotate(9deg); }

例二:與 translate 結合,沿 X 與 Y 移動。

div { width:100px; height:75px; background-color:yellow; border:1px solid black; transition: transform 2s; } 
div:hover { transform: translate(50px, 100px); }

例三:與 scale 結合,滑鼠移入時寬高放大為原本兩倍。

div { width:100px; height:75px; background-color:yellow; border:1px solid black; transition: transform 1s; } 
div:hover { transform: scale(2, 2); }

例四:與 skew 結合,圍繞 X 軸傾斜 30 度、Y 軸傾斜 20 度。

div { width:100px; height:75px; background-color:yellow; border:1px solid black; transition: transform 2s; } 
div:hover { transform: skew(30deg, 20deg); }

來源:https://www.cnblogs.com/zqzjs/

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved