I'm having trouble getting my grid template to stretch content to the end using CSS Grid. The behavior is unexpected, and I want to create a Jeopardy game where clicking on a box reveals a question.
Initially, I applied display: grid
to the body element.
Note that I do not want to involve the ::after
pseudo-element in this issue.
body {
display: grid;
grid-template-columns: repeat(4, 25%);
grid-template-rows: repeat(5, 20%);
height: 100vh;
}
.question-block {
/* attempting to stretch content */
grid-row: 1/-1;
}
Below is a snippet of the code:
* {
box-sizing: border-box;
}
body {
display: grid;
grid-template-columns: repeat(4, 25%);
grid-template-rows: repeat(5, 20%);
height: 100vh;
}
p {
margin: 0;
}
.question-block {
/* attempting to stretch content */
grid-row: 1/-1;
}
.question-block * {
border: 2px solid black;
}
.category {
padding: 1em;
word-wrap: break-word;
font-size: max(1rem, min(1rem + 3vw, 3.5rem));
}
.question {
font-size: 0;
}
.q100::after {
content: "100$";
}
.q200::after {
content: "200$";
}
.q300::after {
content: "300$";
}
.q400::after {
content: "400$";
}
.text-helper::after {
display: block;
padding-block: 0;
text-align: center;
font-size: max(1.5rem, min(1rem + 3vw, 5rem));
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://necolas.github.io/normalize.css/8.0.1/normalize.css" />
<link rel="stylesheet" href="style/style.css" />
<title>Jeopardy</title>
</head>
<body>
<div class="question-block">
<p class="category">Entertainment: Television</p>
<p class="question q100 text-helper">AMC's "The Walking Dead", Rick, Carl, Daryl, Morgan, Carol and Maggie were
introduced to us in Season 1.</p>
<p class="question q200 text-helper">In the TV series Red Dwarf, Kryten's full name is Kryten 2X4B-523P.</p>
<p class="question q300 text-helper">Like his character in "Parks and Recreation", Aziz Ansari was born in South
Carolina.</p>
<p class="question q400 text-helper">In "Star Trek", Klingons respect William Shakespeare, they even suspect him
having a Klingon lineage.</p>
</div>
<div class="question-block">
<p class="category">Science: Computers</p>
<p class="question q100 text-helper">The very first recorded computer "bug" was a moth found inside a Harvard
Mark II computer.</p>
<p class="question q200 text-helper">Linus Torvalds created Linux and Git.</p>
<p class="question q300 text-helper">It's not possible to format a write-protected DVD-R Hard Disk.</p>
<p class="question q400 text-helper">The Python programming language gets its name from the British comedy group
"Monty Python."</p>
</div>
<div class="question-block">
<p class="category">Vehicles</p>
<p class="question q100 text-helper">Arriva is owned by the Deutsche Bahn.</p>
<p class="question q200 text-helper">Ferrari has never made a V10 engine for any of its cars.</p>
<p class="question q300 text-helper">The General Motors EV1 was the first street-legal production electric
vehicle.</p>
<p class="question q400 text-helper">BMW M GmbH is a subsidiary of BMW AG that focuses on car performance.</p>
</div>
<div class="question-block">
<p class="category">Entertainment: Board Games</p>
<p class="question q100 text-helper">In the game "Racko" you may pick up ANY card from the discard pile.</p>
<p class="question q200 text-helper">The Angry Video Game Nerd's alter ego is "Board James".</p>
<p class="question q300 text-helper">"PAYDAY: The Heist" is a sequel to the board game "Payday".</p>
<p class="question q400 text-helper">The board game Go has more possible legal positions than the number of
atoms in the visible universe.</p>
</div>
<!-- <script src="js/index.js"></script> -->
</body>
</html>
When I change .question-block
to display: grid
, it causes content overlapping issues. Below is the updated code:
* {
box-sizing: border-box;
}
body {
display: grid;
grid-template-columns: repeat(4, 25%);
grid-template-rows: repeat(5, 20%);
height: 100vh;
}
p {
margin: 0;
}
.question-block {
/* attempting to stretch content */
/* modified property here */
display: grid;
/* above */
grid-row: 1/-1;
}
.question-block * {
border: 2px solid black;
}
.category {
padding: 1em;
word-wrap: break-word;
font-size: max(1rem, min(1rem + 3vw, 3.5rem));
}
.question {
font-size: 0;
}
.q100::after {
content: "100$";
}
.q200::after {
content: "200$";
}
.q300::after {
content: "300$";
}
.q400::after {
content: "400$";
}
.text-helper::after {
display: block;
padding-block: 0;
text-align: center;
font-size: max(1.5rem, min(1rem + 3vw, 5rem));
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://necolas.github.io/normalize.css/8.0.1/normalize.css" />
<link rel="stylesheet" href="style/style.css" />
<title>Jeopardy</title>
</head>
<body>
<div class="question-block">
<p class="category">Entertainment: Television</p>
<p class="question q100 text-helper">AMC's "The Walking Dead", Rick, Carl, Daryl, Morgan, Carol and Maggie were
introduced to us in Season 1.</p>
<p class="question q200 text-helper">In the TV series Red Dwarf, Kryten's full name is Kryten 2X4B-523P.</p>
<p class="question q300 text-helper">Like his character in "Parks and Recreation", Aziz Ansari was born in South
Carolina.</p>
<p class="question q400 text-helper">In "Star Trek", Klingons respect William Shakespeare, they even suspect him
having a Klingon lineage.</p>
</div>
<div class="question-block">
<p class="category">Science: Computers</p>
<p class="question q100 text-helper">The very first recorded computer "bug" was a moth found inside a Harvard
Mark II computer.</p>
<p class="question q200 text-helper">Linus Torvalds created Linux and Git.</p>
<p class="question q300 text-helper">It's not possible to format a write-protected DVD-R Hard Disk.</p>
<p class="question q400 text-helper">The Python programming language gets its name from the British comedy group
"Monty Python."</p>
</div>
<div class="question-block">
<p class="category">Vehicles</p>
<p class="question q100 text-helper">Arriva is owned by the Deutsche Bahn.</p>
<p class="question q200 text-helper">Ferrari has never made a V10 engine for any of its cars.</p>
<p class="question q300 text-helper">The General Motors EV1 was the first street-legal production electric
vehicle.</p>
<p class="question q400 text-helper">BMW M GmbH is a subsidiary of BMW AG that focuses on car performance.</p>
</div>
<div class="question-block">
<p class="category">Entertainment: Board Games</p>
<p class="question q100 text-helper">In the game "Racko" you may pick up ANY card from the discard pile.</p>
<p class="question q200 text-helper">The Angry Video Game Nerd's alter ego is "Board James".</p>
<p class="question q300 text-helper">"PAYDAY: The Heist" is a sequel to the board game "Payday".</p>
<p class="question q400 text-helper">The board game Go has more possible legal positions than the number of
atoms in the visible universe.</p>
</div>
<!-- <script src="js/index.js"></script> -->
</body>
</html>