媒体查询和转换的问题

Trouble with media query and transitions

我的目标是当用户进入纵向模式时,图像会出现几秒钟然后关闭。
我已经尝试了可见性、宽度、高度,display.It 并不是真正设置 属性 的问题,而是一个时间问题。我似乎无法弄清楚如何在进入纵向模式时切换可见性等设置,然后在几秒钟后以纯 CSS

将其关闭

这是规格

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <title></title>
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes">

  <style type="text/css">
    body {
      margin: 0;
      padding: 0;
    }
    .orientation {
      position: absolute;
      overflow: hidden;
      top: 0;
      left: 0;
      height: 100%;
      width: 100%;
      min-width: 200px;
      min-height: 200px;
    }
    .orientation .outerDiv {
      position: absolute;
      overflow: hidden;
      height: 100%;
      width: 100%;
    }
    .orientation .innerDiv {
      position: absolute;
      overflow: hidden;
      left: 50%;
      top: 50%;
      margin-left: -100px;
      margin-top: -100px;
      background-image: url('rotate.gif');
      background-repeat: no-repeat;
      width: 200px;
      height: 200px;
    }
    @media all and (orientation: portrait) {
      .orientation {}
    }
    @media all and (orientation: landscape) {
      .orientation {}
    }
  </style>

</head>

<body>
  <div class="orientation">
    <div class="outerDiv">
      <div class="innerDiv"></div>
    </div>
  </div>
</body>

</html>
</code>

您可以使用 CSS3 动画来完成。我在 jsfiddle 上做了一个例子:https://jsfiddle.net/h532fxz4/(减少 "result" 框的宽度,使其像 "portrait" 视图)。经过我修改后的代码现在如下所示:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes">

    <style type="text/css">
        body {
            margin: 0;
            padding: 0;
        }
        .orientation {
            position: absolute;
            overflow: hidden;
            top: 0;
            left: 0;
            height: 100%;
            width: 100%;
            min-width: 200px;
            min-height: 200px;
            opacity: 0;
        }

        .orientation .outerDiv {
            position: absolute;
            overflow: hidden;
            height: 100%;
            width: 100%;
        }
        .orientation .innerDiv {
            position: absolute;
            overflow: hidden;
            left: 50%;
            top: 50%;
            margin-left: -100px;
            margin-top: -100px;
            background-image: url('rotate.gif');
            background-repeat: no-repeat;
            width: 200px;
            height: 200px;
        }

        @-webkit-keyframes show-out {
            0% {
                opacity: 1;
            }
            100% {
                opacity: 0;
            }
        }
        @keyframes show-out {
            0% {
                opacity: 1;
            }
            100% {
                opacity: 0;
            }
        }

        @media all and (orientation: portrait) {
            .orientation {
                opacity: 0;
                animation-name: show-out;
                animation-duration: 0.5s;
                 animation-delay: 2s;
                animation-fill-mode: backwards;
                animation-timing-function: linear;
            }
        }
        @media all and (orientation: landscape) {
            .orientation {}
        }
    </style>
</head>
<body>
    <div class="orientation">
        <div class="outerDiv">
            <div class="innerDiv"><img src="https://upload.wikimedia.org/wikipedia/en/2/21/EverestfromKalarPatarcrop.JPG" alt=""></div>
        </div>
    </div>
</body> 
</html>

澄清一下:
- show/hide 属性 是 "opacity" (可以动画)
- 在媒体查询中 "orientation: portrait" 我添加了动画属性,您可以在其中设置时间延迟(隐藏图像的效果应该开始的时间)和动画持续时间(过渡应该持续多长时间)。
- 关键帧(用于 webkit 和其他浏览器),它定义了不透明度应该如何改变。
- 据我所知,如果没有一些 JavaScript 代码,在纯 CSS 中 "never show img again" 是不可能的。