编辑下面的代码:【加编码】
<html> <head> <style> #DIV1 { position: relative; height: 200px; width: 200px; margin: 100px; padding:10px; border: 1px solid black; } #DIV2 { padding:50px; position: absolute; border: 1px solid black; background-color: coral; transform: rotateY(50deg); -webkit-transform: rotateY(50deg); /* Opera、Chrome 和 Safari */ } #DIV3 { padding:40px; position: absolute; border: 1px solid black; background-color: lightblue; transform: rotateY(70deg); -webkit-transform: rotateY(70deg); /* Opera、Chrome 和 Safari */ } </style> </head> <body> <p>点击“尝试一下”按钮,让 DIV2 元素的子元素保留其 3D 位置:</p> <button onclick="myFunction()">尝试一下</button> <div id="DIV1">DIV1 <div id="DIV2">HELLO DIV2 <div id="DIV3">HELLO DIV3</div> </div> </div> <script> function myFunction() { document.getElementById("DIV2").style.transformStyle = "preserve-3d"; /* Opera、Chrome 和 Safari */ document.getElementById("DIV2").style.WebkitTransformStyle = "preserve-3d"; } </script> <p>Firefox 支持 transformStyle 属性。</p> <p>Chrome 和 Safari 支持另一个可替代该属性的属性,即 WebkitTransformStyle 属性。</p> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂