I'm trying to learn CSS to some extent. I had following code where when resizing logo and table style would overflow table.
<!DOCTYPE html>
<html>
<head>
<style>
.grid-container {
display: grid;
grid-template-columns: auto; /* auto auto; */
background-color: #2196f3;
padding: 10px;
}
.grid-item {
background-color: rgba(255, 255, 255, 0.8);
border: 1px solid rgba(0, 0, 0, 0.8);
padding: 20px;
font-size: 30px;
text-align: center;
}
</style>
</head>
<body>
<h1>Grid Elements</h1>
<p>
A Grid Layout must have a parent element with the
<em>display</em> property set to <em>grid</em> or
<em>inline-grid</em>.
</p>
<p>
Direct child element(s) of the grid container automatically becomes
grid items.
</p>
<div class="grid-container">
<div class="grid-item">
<img
src="https://evotec.xyz/wp-content/uploads/2015/05/Evotec-Logo-190x41.png"
alt="DefaultAlternativeText"
width="DefaultWidth"
height="DefaultHeight"
/>
</div>
<div class="grid-item">
<img
src="https://evotec.xyz/wp-content/uploads/2015/05/Evotec-Logo-600x190.png"
alt="DefaultAlternativeText"
width="DefaultWidth"
height="DefaultHeight"
/>
</div>
<div class="grid-item">3</div>
<div class="grid-item">4</div>
<div class="grid-item">5</div>
<div class="grid-item">6</div>
<div class="grid-item">7</div>
<div class="grid-item">8</div>
<div class="grid-item">9</div>
</div>
</body>
</html>
Using 3 new settings fixed that for me to some extent:
<!DOCTYPE html>
<html>
<head>
<style>
.grid-container {
display: grid;
grid-template-columns: auto; /* auto auto; */
background-color: #2196f3;
padding: 10px;
}
.grid-item {
background-color: rgba(255, 255, 255, 0.8);
border: 1px solid rgba(0, 0, 0, 0.8);
padding: 20px;
font-size: 30px;
text-align: center;
/* Addeed */
overflow: hidden; /* NEW */
min-height: 0; /* NEW */
min-width: 0; /* NEW; needed for Firefox */
}
</style>
</head>
<body>
<h1>Grid Elements</h1>
<p>
A Grid Layout must have a parent element with the
<em>display</em> property set to <em>grid</em> or
<em>inline-grid</em>.
</p>
<p>
Direct child element(s) of the grid container automatically becomes
grid items.
</p>
<div class="grid-container">
<div class="grid-item">
<img
src="https://evotec.xyz/wp-content/uploads/2015/05/Evotec-Logo-190x41.png"
alt="DefaultAlternativeText"
width="DefaultWidth"
height="DefaultHeight"
/>
</div>
<div class="grid-item">
<img
src="https://evotec.xyz/wp-content/uploads/2015/05/Evotec-Logo-600x190.png"
alt="DefaultAlternativeText"
width="DefaultWidth"
height="DefaultHeight"
/>
</div>
<div class="grid-item">3</div>
<div class="grid-item">4</div>
<div class="grid-item">5</div>
<div class="grid-item">6</div>
<div class="grid-item">7</div>
<div class="grid-item">8</div>
<div class="grid-item">9</div>
</div>
</body>
</html>
Now there's no overflow, the first image gets centered to fit, 2nd image is cut. Which is somewhat ok.
My questions:
- What would be the solution to get that image to resize to fit?
- Will that solution work for other types of data within that grid? I'm planning to use http://datatables.net and put tables within that grid. I want to make sure the table is readable and not overflow.
Is there a way to prevent grid item to go beyone certain size? Like if datatable is required to be certain size, and user opens it on smaller size I would prefer to get scroller bottom / top then make it broken.
There is
grid-template-columns: auto;I'm adding more auto auto auto to get more columns. What would be the way so that when there is a certain size it's 3 columns, but when it goes down it becomes 2 columns and then 1 column when it's minimal. How can I achieve that in a way where it would work in a most efficient way that wouldn't require me to change things all the time.- Is there a way to stop the browser from resizing further (making it smaller)? I would like to stop the user resizing browser so that things are readable.