红,绿,蓝哪个在最上方

来源:2-14 编程练习

ZFB8672236

2022-09-13 11:43:00

<!Doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>空间移动</title>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    .box {
        width: 200px;
        height: 200px;
        margin: 200px auto;
        perspective: 300px;
        position: relative;
    }

    .box p {
        position: absolute;
        left: 0;
        top: 0;
        width: 200px;
        height: 200px;
    }

    /* 补充代码 */
    .box p:nth-child(1) {
        background-color: red;
        transform: translateZ(20px);
    }
    .box p:nth-child(2) {
        background-color: green;

    }
    .box p:nth-child(3) {
        background-color: blue;
        transform: translateZ(-50px);
    }
</style>
</head>
<body>
<div class="box">
    <p></p>
    <p></p>
    <p></p>
</div>
</body>
</html>

红色块向我们眼睛的方向移动了20px,离眼睛最近,近大远小,感觉应该压盖绿、蓝色块,实际效果是这样:

https://img.mukewang.com/climg/631ffbee09aee5c603270319.jpg

写回答

1回答

好帮手慕久久

2022-09-13

同学你好,按照近大远小的常识来看,红色是最近的,所以看着最大;蓝色是最远的,所以最小:

https://img.mukewang.com/climg/631ffd8d09aaea0f05690392.jpg

由于当前展示的是2d平面效果,为了显示所有元素,浏览器处理后的颜色压盖效果感觉不太对。

建议换成3d效果查看:

https://img.mukewang.com/climg/631ffdd209f13acf07050281.jpg

https://img.mukewang.com/climg/631ffdee0941a86c04410322.jpg

2d效果与实际的3d效果是有差别的,简单知道就行了。

祝学习愉快!

0

0 学习 · 17877 问题

查看课程