<html>
<head>
<style>
#div1
{
position: relative;
margin:auto;
height: 150px;
width: 250px;
padding:10px;
border: 1px solid black;
-webkit-perspective:200px; /* Chrome, Safari, Opera */
perspective:200px;
}
#div2
{
padding:50px;
position: absolute;
border: 1px solid black;
background-color: red;
-webkit-transform: rotateX(45deg); /* Chrome、Safari、Opera */
transform: rotateX(45deg);
}
</style>
</head>
<body>
<p>点击“尝试一下”按钮,改变 DIV1 元素的 perspective 属性:</p>
<button onclick="myFunction()">尝试一下</button>
<div id="div1">DIV1
<div id="div2">假设您是一只鸟,从上往下看墙面。然后点击按钮来看看当您改变视角时会发生什么!</div>
</div>
<script>
function myFunction()
{
document.getElementById("div1").style.perspective = "100px";
/* Safari 和 Chrome */
document.getElementById("div1").style.WebkitPerspective = "100px";
}
</script>
</body>
</html>