這篇文章所說的內容是純CSS實作3D的程式碼(正方體、動態立體圖片冊、平面的星空),程式碼都非常詳細,有需要的朋友可以看一下。
一、正方體
我認為正方體可以算是3D影像的基礎吧,首先正方體是由六個相同的面所組成,其次就需要我們依序構造。 (據體建構在程式碼中)
程式碼如下:
nbsp;html> <meta> <meta> <meta> <title>正方体</title> <style> .d3{ height: 300px; width:300px; perspective: 800px; margin:140px auto; border:1px solid #ccc; } .stage{ height: 300px; width: 300px; transform-style: preserve-3d; position: relative; transform: rotateX(45deg) rotateY(45deg); } .role{ height: 300px; width: 300px; position: absolute; } .stage{ animation: dong 3s linear infinite;(这是舞台) } .stage:hover{ animation: paused; } @keyframes dong{(这是使舞台旋转的动画) from{ transform: rotateX(45deg) rotateY(45deg); } to{ transform: rotateX(405deg) rotateY(405deg); } } .di1{(正方体的前面) background: rgb(21, 163, 52); transform: translateZ(150px);(沿着z轴向前移动150px) font-size:100px; font-family:KaiTi; text-align: center; line-height: 300px; } .di2{(正方体的后面) background: blue; transform: translateZ(-150px) rotateY(180deg);(沿着z轴向前移动150px然后沿着y轴旋转180°*注意顺序哦是先移动后旋转) font-size:100px; font-family:KaiTi; text-align: center; line-height: 300px; } .di3{(正方体的左面) background: purple; transform: rotateY(-90deg) translateZ(150px); font-size:100px; font-family:KaiTi; text-align: center; line-height: 300px; } .di4{(正方体的右面) background: pink; transform: rotateY(90deg) translateZ(150px); font-size:100px; font-family:KaiTi; text-align: center; line-height: 300px; } .di5{(正方体的上面) background: red; transform: rotateX(90deg) translateZ(150px); font-size:100px; font-family:KaiTi; text-align: center; line-height: 300px; } .di6{(正方体的下面) background: yellow; transform: rotateX(-90deg) translateZ(150px); font-size:100px; font-family:KaiTi; text-align: center; line-height: 300px; } </style> <div> <div> (将正方体分为六个相同的面) <div>前</div> <div>后</div> <div>左</div> <div>右</div> <div>上</div> <div>下</div> </div> </div>
二、動態立體圖片冊
將圖片集設計成本體3D的效果
利用旋轉、移動、傾斜和3D效果讓你的圖冊更漂亮。
程式碼如下:
(将第一张定好位置后将后面的依次排列) nbsp;html> <meta> <meta> <meta> <title>事例一</title> <style> body{ height: 100vh; } .div { height: 500px; width: 800px; perspective: 800px; margin: 50px auto; } .div1 { height: 500px; width: 800px; transform-style: preserve-3d; position: relative; /* transform: rotateY(-10deg); */ } .div_0{ height:400px; width:600px; position: absolute; margin-top:110px; margin-left:50px; } .div_1{ height:400px; width:600px; background: url(../day03/timg.jpg); background-size: 600px 400px; border-radius: 20px; transform-origin: right bottom; transition: 3s; } .div_2{ background: url(../day03/timg1.jpg); border-radius: 20px; background-size: 600px 400px; transform-origin: right bottom; transform: rotateZ(2deg) translateZ(-20px) translateX(20px) translateY(-20px); } .div_2:hover{ transform: rotateZ(0) translateZ(0)translateX(0)translateY(0); transition: 1s; } .div_2:hover~.div_1{ /* transform-origin: right bottom; */ transform: rotateZ(2deg) translateZ(20px) translateX(20px) translateY(-20px); transition: 1s; } /* body:hover .div_1{ opacity: 0; transition: 3s; } */ .div_3{ background: url(timg2.jpg); border-radius: 20px; background-size: 600px 400px; transform-origin: right bottom; transform: rotateZ(4deg)translateZ(-40px)translateX(40px)translateY(-40px); } .div_3:hover{ transform: rotateZ(0) translateZ(0)translateX(0)translateY(0); transition: 1s; } .div_4{ background: url(timg4.jpg); border-radius: 20px; background-size: 600px 400px; transform-origin: right bottom; transform: rotateZ(6deg)translateZ(-60px) translateX(60px)translateY(-60px); } .div_4:hover{ transform: rotateZ(0) translateZ(0)translateX(0)translateY(0); transition: 1s; } .div_5{ background: url(timg5.jpg); border-radius: 20px; background-size: 600px 400px; transform-origin: right bottom; transform: rotateZ(8deg)translateZ(-80px) translateX(80px)translateY(-80px); } .div_5:hover{ transform: rotateZ(0) translateZ(0)translateX(0)translateY(0); transition: 1s; } .div_6{ background: url(timg3.jpg) no-repeat; border-radius: 20px; background-size: 600px 400px; transform-origin: right bottom; transform: rotateZ(10deg)translateZ(-100px) translateX(100px)translateY(-100px); } .div_6:hover{ transform: rotateZ(0) translateZ(0)translateX(0)translateY(0); transition: 1s; } </style> <div> <div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> </div> </div>
三、平面的星空
程式碼如下:
(由於沒有用js所以只有平面的效果了
你掌握好旋轉的中心點就很容易了)
nbsp;html> <meta> <meta> <meta> <title>太阳系</title> <style> body { background: url(timg01.jpg) no-repeat; background-size: 100%; } .box1 { height: 600px; width: 600px; margin: 0 auto; border: 1px solid #ccc; border-radius: 50%; } .box1_0 { height: 100px; width: 100px; margin: 0 auto; border: 1px solid white; border-radius: 50%; position: absolute; top: calc(50% - 59px); left: 322px; transform-origin: 345.5px; animation: dong2 5s linear infinite 4s; } @keyframes dong2 { from { transform: rotate(0) } 100% { transform: rotate(360deg); } } .box1_2 { height: 13px; width: 13px; margin: 0 auto; /* border: 1px solid #ccc; */ border-radius: 50%; background: white; position: absolute; top: calc(50% - 7.5px); left: 96px; transform-origin: -45px; animation: dong3 5.5s linear infinite ; /* animation-iteration-count: 200; */ } @keyframes dong3 { from { transform: rotate(0); } 100% { transform: rotate(360deg); } } .box1_1 { height: 15px; width: 15px; margin: 0 auto; /* border: 1px solid #ccc; */ border-radius: 50%; background: rgb(7, 100, 223); position: absolute; top: 45px; left: calc(50% - 16.5px); } .box2 { height: 400px; width: 400px; margin: 0 auto; border: 1px solid #ccc; border-radius: 50%; position: absolute; top: calc(50% - 200px); left: calc(50% - 200px); } .box2_1 { height: 15px; width: 15px; margin: 0 auto; /* border: 1px solid #ccc; */ border-radius: 50%; background: rgb(198, 208, 221); position: absolute; top: calc(50% - 7.5px); left: 43px; transform-origin: 157.5px; animation: dong1 5s linear infinite .5s; } @keyframes dong1 { from { transform: rotate(0) } 100% { transform: rotate(360deg); } } .box2_2 { height: 15px; width: 15px; margin: 0 auto; border-radius: 50%; background: #644e11; position: absolute; top: calc(50% - 7.5px); left: -7px; transform-origin: 207.5px; animation: dong 5s linear infinite; } @keyframes dong { from { transform: rotate(0) } 100% { transform: rotate(360deg); } } .box3 { height: 300px; width: 300px; margin: 0 auto; border: 1px solid #ccc; border-radius: 50%; position: absolute; top: calc(50% - 150px); left: calc(50% - 150px); } .box4 { height: 30px; width: 30px; margin: 0 auto; border-radius: 50%; background: orange; position: absolute; top: calc(50% - 15px); left: calc(50% - 15px); } .boxli{ height: 900px; width: 900px; margin: 0 auto; border: 1px solid #ccc; border-radius: 50%; position: absolute; top:-120px; left:calc(50% - 450px); } .boxli_1{ height: 15px; width: 15px; margin: 0 auto; border-radius: 50%; background: rgb(116, 100, 56); position: absolute; top:500px; left:-6px; transform-origin: 455.5px -38px; animation: dongli 5s linear infinite; } @keyframes dongli { from { transform: rotate(0) } 100% { transform: rotate(360deg); } } </style> <div> <div> <div></div> <div></div> </div> <div> <div></div> <div></div> <div> <div></div> </div> </div> </div> <div> <div></div> </div>
相關推薦:
#以上是純CSS實現3D的程式碼(立方體、動態立體圖片冊、平面的星空)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

在這篇文章中,布萊克·莫里(Blackle Mori)向您展示了一些駭客,同時試圖推動同位HTML支持的極限。如果您敢於使用這些,以免您也被標記為CSS罪犯。

具有CSS的自定義光標很棒,但是我們可以將JavaScript提升到一個新的水平。使用JavaScript,我們可以在光標狀態之間過渡,將動態文本放置在光標中,應用複雜的動畫並應用過濾器。

互動CSS動畫和元素相互啟動的元素在2025年似乎更合理。雖然不需要在CSS中實施乒乓球,但CSS的靈活性和力量的增加,可以懷疑Lee&Aver Lee有一天會成為一種

有關利用CSS背景濾波器屬性來樣式用戶界面的提示和技巧。您將學習如何在多個元素之間進行背景過濾器,並將它們與其他CSS圖形效果集成在一起以創建精心設計的設計。

好吧,事實證明,SVG的內置動畫功能從未按計劃進行棄用。當然,CSS和JavaScript具有承載負載的能力,但是很高興知道Smil並沒有像以前那樣死在水中

是的,讓#039;跳上文字包裝:Safari Technology Preview In Pretty Landing!但是請注意,它與在鉻瀏覽器中的工作方式不同。

此CSS-tricks更新了,重點介紹了年鑑,最近的播客出現,新的CSS計數器指南以及增加了幾位新作者,這些新作者貢獻了有價值的內容。

在大多數情況下,人們展示了@Apply的@Apply功能,其中包括Tailwind的單個property實用程序之一(會改變單個CSS聲明)。當以這種方式展示時,@Apply聽起來似乎很有希望。如此明顯


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能