Let's say that I want to create a grid with four square <div>
elements inside.
I want to set the square sizes to a constant value, so even if a square will have content inside that is larger then the size of the square, the square will remain in the same size, and the content will not 'exit' the square.
To demonstrate the problem, I have created the example below. Thanks in advance! (:
#one { grid-area: "one"; }
#two { grid-area: "two"; }
#three { grid-area: "three"; }
#four { grid-area: "four"; }
#container {
display: grid;
grid-gap: 10px;
width: 200px;
height: 200px;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;
grid-template:
"one two"
"three four";
background: gray;
color: white;
}
.square {
background: black;
white-space: nowrap; /* Not working... */
}
Original:
<div id="container">
<div class="square" id="one"></div>
<div class="square" id="two"></div>
<div class="square" id="three"></div>
<div class="square" id="four"></div>
</div>
<br />
Adding text:
<div id="container">
<div class="square" id="one">
<h1>Hello \:</h1>
</div>
<div class="square" id="two"></div>
<div class="square" id="three"></div>
<div class="square" id="four"></div>
</div>
<br />
Expected result:<br />
<img src="https://imgur.com/xWpRShk.png" />