CSS3 3D效果基礎(chǔ)版本

3D變換,3個(gè)屬性

  • transform-style: prevserve-3d ;建立3D空間,必須是父元素,運(yùn)動(dòng)的元素沒法建立
  • perspective:數(shù)字 景深
  • perspective-origin 景深基點(diǎn): 視線是從哪個(gè)方向看過去的
  • transform : 新增函數(shù)
    • rotateX() 旋轉(zhuǎn)X軸 類似單杠
    • rotateY() 旋轉(zhuǎn)Y軸 類似鋼管舞
    • rotateZ() 旋轉(zhuǎn)Z軸 類似水平翻轉(zhuǎn)
    • translateZ() 位移Z軸,簡(jiǎn)單來(lái)說就是近大遠(yuǎn)小
    • scaleZ() 放大

這里特別提醒用了3D空間必須加相對(duì)定位

圍繞X軸旋轉(zhuǎn)

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv='Content-Type' content="text/html; charset=utf-8">
    <meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
    <title>3D旋轉(zhuǎn)</title>
</head>
<style>
    *{margin:0px;padding:0px;}
    h1{margin:10px auto;position:absolute;left:50%;top:0px;-webkit-transform: translate(-50%,0);}
    div{width:100px;height:100px;padding:100px;border:10px solid black;-webkit-perspective: 50px;-webkit-transform-style: preserve-3d;}
    p{width:100px;height:100px;background:red;transition: 2s;}
    div:hover p {
        -webkit-transform: rotateX(180deg);
    }
</style>
<body>
<h1>鼠標(biāo)放到框子上面就會(huì)變形</h1>
  <div>
      <p>

      </p>
  </div>
</body>
</html>

效果圖

圍繞X軸旋轉(zhuǎn).gif

繞Y軸旋轉(zhuǎn)

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv='Content-Type' content="text/html; charset=utf-8">
    <meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
    <title>繞Y軸旋轉(zhuǎn)</title>
</head>
<style>
    *{margin:0px;padding:0px;}
    div{width:100px;height:100px;padding: 100px;border:10px solid blanchedalmond;-webkit-transform-style: preserve-3d;-webkit-perspective: 100px;margin:0 auto;}
    p{width:100px;height:100px;background:red;transition: 2s;line-height:100px;text-align:center;}
    p span{transition: 1s;}
    div:hover p{-webkit-transform: rotateY(180deg) ;}
    div:hover p span{-webkit-transform: rotateY(-180deg) ;display:block;}
</style>
<body>
  <div>
       <p>
           <span>2</span>
       </p>
  </div>
<!--小提示要是里面的文字不轉(zhuǎn)的話可以給里面的文字設(shè)定一個(gè)包裹層這樣也旋轉(zhuǎn)了-->
</body>
</html>

效果圖

圍繞y軸旋轉(zhuǎn).gif

繞Z軸旋轉(zhuǎn)

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv='Content-Type' content="text/html; charset=utf-8">
    <meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
    <title>TranslateZ</title>
</head>
<style>
    *{margin:0px;padding:0px;}
    div{width:100px;height:100px;padding:100px;margin:0 auto;border:10px solid #ccc;-webkit-perspective: 100px;-webkit-transform-style: preserve-3d;}
    p{width:100px;height:100px;background:red;transition: 2s;}
    div:hover p {-webkit-transform: translateZ(-100px);}
</style>
<body>
<div>
    <p>
        1
    </p>
</div>
</body>
</html>

效果圖 近大遠(yuǎn)小

圍繞Z軸旋轉(zhuǎn).gif
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • CSS里transform變形這個(gè)屬性有點(diǎn)學(xué)習(xí)難度,尤其在CSS3里加上了3D效果之后,2維變3維學(xué)習(xí)成本更是成倍...
    張歆琳閱讀 28,363評(píng)論 5 81
  • 一、寫在前面的秋褲 早在去年的去年,我就大肆介紹了2D transform相關(guān)內(nèi)容。看過海賊王的都知道,帶D的家伙...
    MrZengB閱讀 1,403評(píng)論 2 9
  • 看了很多視頻、文章,最后卻通通忘記了,別人的知識(shí)依舊是別人的,自己卻什么都沒獲得。此系列文章旨在加深自己的印象,因...
    DCbryant閱讀 1,963評(píng)論 0 4
  • 當(dāng)我看到下面這張基本圖的時(shí)候,我的右側(cè)的濃眉毛不由自主抖動(dòng)了兩下,呵,呵呵~~ rotateY( angle ) ...
    追風(fēng)逸少丶閱讀 1,620評(píng)論 0 3
  • 關(guān)于css3變形 CSS3變形是一些效果的集合,比如平移、旋轉(zhuǎn)、縮放和傾斜效果,每個(gè)效果都被稱作為變形函數(shù)(Tra...
    hopevow閱讀 6,564評(píng)論 2 13

友情鏈接更多精彩內(nèi)容