CSS SNIPPET

  返回

使用全屏伪类  视觉效果

使用:fullscreen CSS 伪类的元素仅在全屏模式显示。

HTML
<div class="container">
  <p><em>Click the button below to enter the element into fullscreen mode. </em></p>
  <div class="element" id="element"><p>I change color in fullscreen mode!</p></div>
  <br />
  <button onclick="var el = document.getElementById('element'); el.requestFullscreen();">
    Go Full Screen!
  </button>
</div>
CSS
.container {
  margin: 40px auto;
  max-width: 700px;
}

.element {
  padding: 20px;
  height: 300px;
  width: 100%;
  background-color: skyblue;
  box-sizing: border-box;
}

.element p {
  text-align: center;
  color: white;
  font-size: 3em;
}

.element:-ms-fullscreen p {
  visibility: visible;
}

.element:fullscreen {
  background-color: #e4708a;
  width: 100vw;
  height: 100vh;
}
效果演示

Click the button below to enter the element into fullscreen mode.

I change color in fullscreen mode!


代码说明
  1. fullscreen CSS 伪类选择符用于选中并设置在全屏模式下显示的元素的样式。
浏览器支持

99.1%