m0_46602893
m0_46602893
2021-03-19 00:34
采纳率: 59.1%
浏览 51

backface-visibility: hidden;为什么在我这段代码中显示错误?

<!DOCTYPE html>
<html lang="en">
<head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
      <style>
            *{margin: 0;padding: 0;}
            ul{list-style: none;}
            .box{width: 500px;height: 500px;border: 1px solid black;perspective: 300px;margin: 200px;}
            ul{width: 100px;height: 100px;margin: 100px;position: relative;transform-style: preserve-3d;transition: 2s;transform-origin: center center -50px;}
            li{width: 100px;height: 100px;position: absolute;opacity: 0.3;text-align: center;line-height: 100px;}
            li:nth-child(1){background-color: red;left: 0;top: 0;}
            li:nth-child(2){background-color: blue;left: 100;top: 0;transform-origin: left;transform: rotateY(90deg);}
            li:nth-child(3){background-color: green;left: 0;top: 100;transform-origin: top;transform: rotateX(-90deg);}
            li:nth-child(4){background-color: yellow;left: 0;top: -100;transform-origin: bottom;transform: rotateX(90deg);}
            li:nth-child(5){background-color: purple;left: -100;top: 0;transform-origin: right;transform: rotateY(-90deg);}
            li:nth-child(6){background-color: brown;left: 0;top: 0;transform: translateZ(-100px);}

            .box:hover ul{transform: rotateY(360deg);}
      </style>
</head>
<body>
      <div class="box">
            <ul>
                  <li>1</li>
                  <li>2</li>
                  <li>3</li>
                  <li>4</li>
                  <li>5</li>
                  <li>6</li>
            </ul>
      </div>
</body>
</html>

而且backface-visibility: hidden;为什么不能给ul加而非得给li加?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • r1733209039
    random1123 2021-03-19 10:53
    已采纳

    backface-visibility: hidden;是指当某个元素的背面朝向屏幕时隐藏

    所以要加在li上面,但是由于你的top 和left值非0时没有加px单位,所以值不起作用。而且li6的时候,应该要翻转一下,把它的背面朝向屏幕,transform: translateZ(-100px) rotateX(180deg);

    <style>
    li:nth-child(1){background-color: red;left: 0;top: 0;}
    li:nth-child(2){background-color: blue;left: 100px;top: 0;transform-origin: left;transform: rotateY(90deg);}
    li:nth-child(3){background-color: green;left: 0;top: 100px;transform-origin: top;transform: rotateX(-90deg);}
    li:nth-child(4){background-color: yellow;left: 0;top: -100px;transform-origin: bottom;transform: rotateX(90deg);}
    li:nth-child(5){background-color: purple;left: -100px;top: 0;transform-origin: right;transform: rotateY(-90deg);}
    li:nth-child(6){background-color: brown;transform: translateZ(-100px) rotateX(180deg);}
    li{width: 100px;height: 100px;position: absolute;opacity: .3;text-align: center;line-height: 100px;backface-visibility: hidden;}
    </style>
    点赞 评论
  • qq_34086049
    射手座男人 2021-03-19 10:24

    backface-visibility 属性定义当元素不面向屏幕时是否可见。你的ul并没有反转背向屏幕所以不管用吧

    点赞 评论

相关推荐