本章為大家介紹CSS3實現動態開啟大門效果(程式碼實例)。有一定的參考價值,有需要的朋友可以參考一下,希望對你們有幫助
先看看效果圖:
##動態打開大門效果主要運用到了3D旋轉和定位技術。具體步驟如下:1、先在頁面主體加三個很簡單的div標籤:<div class="door"> <div class="door-l"></div> <div class="door-r"></div> </div>
.door { width: 450px; height: 450px; border: 1px solid #000000; margin: 100px auto; background: url(Images/men.png) no-repeat; background-size: 100% 100%; position: relative; perspective: 1000px; }
.door-l { width: 50%; height: 100%; background-color: brown; position: absolute; top: 0; transition: all 0.5s; left: 0; border-right: 1px solid #000000; transform-origin: left; }
.door-l::before { content: ""; border: 1px solid #000000; width: 20px; height: 20px; position: absolute; top: 50%; border-radius: 50%; transform: translateY(-50%); right: 5px; }
.door:hover .door-l { transform: rotateY(-120deg); }
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>动态打开大门</title> <style> .door { width: 450px; height: 450px; border: 1px solid #000000; margin: 100px auto; background: url(Images/men.png) no-repeat; background-size: 100% 100%; position: relative; perspective: 1000px; } .door-l,.door-r { width: 50%; height: 100%; background-color: brown; position: absolute; top: 0; transition: all 0.5s; } .door-l { left: 0; border-right: 1px solid #000000; transform-origin: left; } .door-r { right: 0; border-left: 1px solid #000000; transform-origin: right; } .door-l::before, .door-r::before { content: ""; border: 1px solid #000000; width: 20px; height: 20px; position: absolute; top: 50%; border-radius: 50%; transform: translateY(-50%); } .door-l::before { right: 5px; } .door-r::before { left: 5px; } .door:hover .door-l { transform: rotateY(-120deg); } .door:hover .door-r { transform: rotateY(120deg); } </style> </head> <body> <div class="door"> <div class="door-l"></div> <div class="door-r"></div> </div> </body> </html>
以上是CSS3實現動態開啟大門效果(程式碼實例)的詳細內容。更多資訊請關注PHP中文網其他相關文章!