2019-07-25
描述
当浏览器为全屏模式时,一个元素上使用 CSS 伪类 :fullscreen
所设定的样式就会被展现出来。
HTML
<div class="container">
<p><em>Click the button below to enter the element into fullscreen mode. </em><button onclick="var el = document.getElementById('element'); el.requestFullscreen();">
Go Full Screen!
</button></p>
<div class="element" id="element"><p>I change color in fullscreen mode!</p></div>
</div>
CSS
.container {
margin: 40px auto;
max-width: 600px;
}
.element {
width: 100%;
background-color: skyblue;
text-align: center;
color: white;
font-size: 3em;
}
.element:-ms-fullscreen p {
visibility: visible;
}
.element:fullscreen {
background-color: #e4708a;
width: 100vw;
height: 100vh;
}
Demo
说明
fullscreen
是 CSS 伪类选择器。当一个元素为全屏模式时,他就可以设定该元素该状态下的样式
浏览器支持
支持率:85.6%
支持情况:https://caniuse.com/#feat=fullscreen
相关文章:https://developer.mozilla.org/en-US/docs/Web/CSS/:fullscreen