Css學習之transform與transition

來源:互聯網
上載者:User

標籤:

在前端開發中,我們常常用到CSS中的transform與transition,那他們的具體用法有哪些呢?今天就和大家分享一二。

transform:轉換

對元素進行移動、縮放、轉動、拉長或展開。

方法:translate():

元素從其當前位置移動,根據給定的 left(x 座標) 和 top(y 座標) 位置參數

有兩個div,它們的css樣式如下:

.before {

width: 70px;

height: 70px;

background-color: #8fbc8f;

}

.after {

width: 70px;

height: 70px;

background-color: #ffe4c4;

-webkit-transform: translate(50px, 30px);

-moz-transform: translate(50px, 30px);

-ms-transform: translate(50px, 30px);

-o-transform: translate(50px, 30px);

transform: translate(50px, 30px);

}


結果如下:

  scale()

元素的尺寸會增加或減少,根據給定的寬度(X 軸)和高度(Y 軸)參數

有兩個div,它們的css樣式如下:

.before {

width: 70px;

height: 70px;

background-color: #8fbc8f;

}

.after {

width: 70px;

height: 70px;

background-color: #ffe4c4;

-webkit-transform: scale(1.5, 0.8);/*寬度變為原來的1.5倍,高度變為原來的0.8倍*/

-moz-transform: scale(1.5, 0.8);

-ms-transform: scale(1.5, 0.8);

-o-transform: scale(1.5, 0.8);

transform: scale(1.5, 0.8);

}


結果如下:


skew()

元素翻轉給定的角度,根據給定的水平線(X 軸)和垂直線(Y 軸)參數

.before {

width: 70px;

height: 70px;

background-color: #8fbc8f;

}

.after {

width: 70px;

height: 70px;

background-color: #ffe4c4;

-webkit-transform: skew(20deg, 20deg);/*圍繞 X 軸把元素翻轉20度,圍繞 Y 軸翻轉20度*/

-moz-transform: skew(20deg, 20deg);

-ms-transform: skew(20deg, 20deg);

-o-transform: skew(20deg, 20deg);

transform: skew(20deg, 20deg);

}


結果如下:

transition:過渡

元素從一種樣式逐漸改變為另一種的效果

有一個div,它的css樣式如下:

div {

width:100px;

height:100px;

background-color: #87cefa;

-webkit-transition: width 2s;/*時間長度為2s的寬度變化效果*/

-moz-transition: width 2s;

-o-transition: width 2s;

transition: width 2s;

}

div:hover{

width:300px;

}


文章來源:HTML5中國

Css學習之transform與transition

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.