--- title: ':fullscreen' slug: 'Web/CSS/:fullscreen' tags: - CSS - CSS Pseudo-class - Experimental - Full-screen - Reference translation_of: 'Web/CSS/:fullscreen' ---
css伪类:fullscreen应用于当前处于全屏显示模式的元素。
它不仅仅选择顶级元素,还包括所有已显示的栈内元素。
:-webkit-full-screen
和:-moz-full-screen。
微软的Edge和Internet Explorer各自使用标准语法::fullscreen
和:-ms-fullscreen。
<div id="fullscreen"> <h1>:fullscreen Demo</h1> <p> This will become a big red text when on fullscreen.</p> <button id="fullscreen-button">Enter Fullscreen</button> </div>
var fullscreenButton = document.getElementById("fullscreen-button"); var fullscreenDiv = document.getElementById("fullscreen"); var fullscreenFunc = fullscreenDiv.requestFullscreen; if (!fullscreenFunc) { ['mozRequestFullScreen', 'msRequestFullscreen', 'webkitRequestFullScreen'].forEach(function (req) { fullscreenFunc = fullscreenFunc || fullscreenDiv[req]; }); } function enterFullscreen() { fullscreenFunc.call(fullscreenDiv); } fullscreenButton.addEventListener('click', enterFullscreen);
#fullscreen:-moz-full-screen { padding: 42px; background-color: pink; border:2px solid #f00; font-size: 200%; } #fullscreen:-ms-fullscreen { padding: 42px; background-color: pink; border:2px solid #f00; font-size: 200%; } #fullscreen:-webkit-full-screen { padding: 42px; background-color: pink; border:2px solid #f00; font-size: 200%; } #fullscreen:-moz-full-screen > h1 { color: red; } #fullscreen:-ms-fullscreen > h1 { color: red; } #fullscreen:-webkit-full-screen > h1 { color: red; } #fullscreen:-moz-full-screen > p { color: DarkRed; } #fullscreen:-ms-fullscreen > p { color: DarkRed; } #fullscreen:-webkit-full-screen > p { color: DarkRed; } #fullscreen:-moz-full-screen > button { display: none; } #fullscreen:-ms-fullscreen > button { display: none; } #fullscreen:-webkit-full-screen > button { display: none; }
#fullscreen:fullscreen { padding: 42px; background-color: pink; border:2px solid #f00; font-size: 200%; } #fullscreen:fullscreen > h1 { color: red; } #fullscreen:fullscreen > p { color: DarkRed; } #fullscreen:fullscreen > button { display: none; }
{{ LiveSampleLink('Example', "(If the 'Enter Fullscreen' button doesn't work, try here)") }}
{{ EmbedLiveSample('Example','80%','200px') }}
特点 | 情况 | 评论 |
---|---|---|
{{SpecName('Fullscreen', '#:fullscreen-pseudo-class', ':fullscreen')}} | {{Spec2('Fullscreen')}} | Initial definition |
{{CompatibilityTable}}
特性 | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
基本支持 |
15.0 {{property_prefix("-webkit")}}[1] | 12 | {{CompatGeckoDesktop("9.0")}}{{property_prefix("-moz")}}[1] {{CompatGeckoDesktop("47.0")}}[2] |
11 {{property_prefix("-ms")}}[3] | {{CompatUnknown}} | 6.0 {{property_prefix("-webkit")}}[1] |
全屏下选取所有元素 | {{CompatUnknown}} | 12 | {{CompatGeckoDesktop(43)}} | 11 | {{CompatUnknown}} | {{CompatUnknown}} |
特性 | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
基本支持 | {{CompatUnknown}} | {{CompatGeckoMobile("9.0")}} {{CompatGeckoDesktop("47.0")}}[2] |
{{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
全屏下选取所有元素 | {{CompatUnknown}} | {{CompatGeckoMobile("43")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
[1] Webkit和Gecko前缀版本在full和screen之间带有破折号, 但W3C标准使用一个单词::fullscreen
, :-webkit-full-screen
, :-moz-full-screen
.
[2] Gecko 47.0 {{geckoRelease("47.0")}} 通过参数full-screen-api.unprefix.enabled使用
不带前缀的伪类, 默认为false.
[3] Internet Explorer使用前缀-ms,但在
full和screen之间没有破折号:-ms-fullscreen
.