CSS基礎 3D導航綜合實戰案例
阿新 • • 發佈:2022-01-07
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> li{ position: relative; list-style: none; float: left; width: 100px; height: 50px; background-color: skyblue; transform-style:preserve-3d; transition: all 1s; transform-origin: bottom; /* 輔助除錯看效果 */ /* transform: rotateX(-20deg) rotateY(30deg);*/ } .nav a{ position: absolute; top: 0; left: 0; display:block; width: 100%; height: 100%; text-decoration: none; color: #fff; text-align: center; line-height: 50px; } .nav li a:first-child{ background-color: pink; transform-origin: top; /*修改預設以盒子的那個方向旋轉*/ } .nav li a:last-child{ transform: rotateX(90deg) translateZ(50px) ; transform-origin: bottom; background-color: orange; } .nav li:hover{ transform: rotateX(-90deg); } </style> </head> <body> <div class="nav"> <ul> <li> <a href="#">首頁</a> <a href="#">Index</a> </li> <li> <a href="#">登入</a> <a href="#">Login</a> </li> <li> <a href="#">註冊</a> <a href="#">Register</a> </li> </ul> </div> </body> </html>