Skip to content

Instantly share code, notes, and snippets.

@jensgro
Created January 23, 2026 13:41
Show Gist options
  • Select an option

  • Save jensgro/507ceb014bbe27ba4d4c0394e29ffb86 to your computer and use it in GitHub Desktop.

Select an option

Save jensgro/507ceb014bbe27ba4d4c0394e29ffb86 to your computer and use it in GitHub Desktop.
Fullscreen API
<div id="root">
<div class="title">This will not go fullscreen</div>
<div id="fullscreen">
<div class="title">This will go fullscreen</div>
<button id="button">Toggle Fullscreen</button>
</div>
</div>
let fullscreen = document.querySelector("#fullscreen");
let button = document.querySelector("#button");
button.addEventListener("click", () => {
if (!document.fullscreenElement) {
fullscreen?.requestFullscreen();
} else {
document.exitFullscreen();
}
});
button {
border: none;
padding: 8px 16px;
background-color: #264653;
color: white;
cursor: pointer;
}
#root {
position: relative;
width: 1000px;
font-size: 24px;
height: 400px;
background-color: #e9c46a;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
#fullscreen {
position: relative;
width: 600px;
height: 200px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #e76f51;
}
#fullscreen:fullscreen {
background-color: red;
width: 75% !important;
max-width: 75% !important;
height: auto !important;
}
#fullscreen::backdrop {
background-color: transparent;
}
#root:fullscreen > #button {
background-color: red;
border: none;
}
.title {
position: absolute;
bottom: 40px;
font-family: roboto;
text-transform: uppercase;
color: #264653;
}
body {
height: 100vh;
width: 100vw;
background-color: #264653;
margin: 0;
box-sizing: border-box;
display: flex;
justify-content: center;
align-items: center;
}
@jensgro
Copy link
Author

jensgro commented Jan 23, 2026

Die Breiteneinschränkung bei #fullscreen:fullscreen haben keinen Effekt. Trotz !important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment