I'm currently working on a small game and I'm trying to make it fit within the browser window without any scrolling necessary. The main layout includes a title section followed by a grid containing various elements, and I'd like them all to resize dynamically based on the window size.
Initially, I attempted using
<body style="height: 100vh">
with height: 5%
for the title and height: 95%
for the grid. However, this led to some overflow and an unwanted scroll bar. I then experimented with height: 5vh
and height: 95vh
for the respective sections, but still faced similar issues.
At this point, I've run out of ideas and haven't been able to find a solution through online searches.
Below is the code snippet:
* {
margin: 0px;
border: 0px;
padding: 0px;
}
body {
background: #007acc;
}
.title {
padding: 1%;
margin: 1% auto;
background: #ff9400;
border: 4px solid black;
border-radius: 20px;
text-align: center;
width: 90%;
}
.grid {
display: grid;
grid-template: auto auto auto auto auto / 70% 30%;
grid-gap: 1%;
width: 85%;
margin: 1% auto;
}
.music {
padding: 1%;
background: grey;
grid-area: 1 / 1 / span 1 / span 1;
font-size: 30px;
}
(chat CSS styles omitted for brevity)
.share {
width: 100%;
height: 100%;
border-radius: 20px;
grid-area: 4 / 2 / span 2 / span 1;
}
HTML structure excluded for readability.