So I have this basic setup - a canvas area and an animator in a parent grid.
The parent grid is also inside another grid with one 1fr row.
I can resize the animator by dragging a resizer up and down.
canvas {
background-color: blue;
}
#grid1 {
grid-template-rows: 1fr;
}
#grid2 {
background-color: black;
display: grid;
grid-template-rows: 1fr auto;
overflow: hidden;
}
#canvas-area {
grid-row: 1;
background-color: red;
}
#animator {
grid-row: 2;
height: 200px;
}
<div id="grid1">
<div id="grid2">
<div id="canvas-area">
<canvas/>
</div>
<div id="animator"></div>
</div>
</div>
I want the canvas to be bigger than its parent and hide its overflow, but that seems to also expand the parent element.
I've already tried overflow: hidden, but that doesn't work
As a side question: I also noticed that there is a space of 4px under the canvas, why is that?
I want the canvas to be bigger than its parent and hide its overflow, but that seems to also expand the parent element.
Normally you'd add a height to the grid container so that the the 1fr in the grid-template-rows: 1fr auto is meaningful; otherwise the grid item auto-adjusts to the dimensions of its contents.
Add overflow: hidden to the grid item #canvas-area along with a fixed height to the container (say 400px as your previous jsFiddle had) - see demo below:
document.querySelector('button').onclick = () => {
document.querySelector('canvas').height = 300;
}
canvas {
background-color: blue;
}
#grid {
background-color: black;
display: grid;
grid-template-rows: 1fr auto;
width: 400px;
height: 400px; /* added a fixed height */
}
#canvas-area {
grid-row: 1;
background-color: red;
overflow: hidden; /* added */
}
#animator {
grid-row: 2;
height: 200px;
}
<div id="grid">
<div id="canvas-area">
<canvas/>
</div>
<div id="animator"></div>
</div>
<button>Change Canvas Height</button>
Note that adding min-height: 0 also does not grow the container:
document.querySelector('button').onclick = () => {
document.querySelector('canvas').height = 300;
}
canvas {
background-color: blue;
}
#grid {
background-color: black;
display: grid;
grid-template-rows: 1fr auto;
width: 400px;
height: 400px;
}
#canvas-area {
grid-row: 1;
background-color: red;
min-height: 0; /* added */
}
#animator {
grid-row: 2;
height: 200px;
}
<div id="grid">
<div id="canvas-area">
<canvas/>
</div>
<div id="animator"></div>
</div>
<button>Change Canvas Height</button>
Why so?
By default grid items have min-width: auto and min-height: auto (just like flex items). You can see some examples of of this behaviour below:
css-grid creates an imaginary column
How to make images stay within the rows of a css grid container?
and from the specs:
To provide a more reasonable default minimum size for grid items, this
specification defines that the auto value of min-width/min-height also
applies an automatic minimum size in the specified axis to grid items
whose overflow is visible and which span at least one track whose min
track sizing function is auto.
W3C
Space below canvas element?
I also noticed that there is a space of 4px under the canvas, why is that?
That is the whitespace, a characteristic of inline elements - you can remove that by making it a block element (add display: block) or adjusting vertical-align property (add vertical-align: top):
document.querySelector('button').onclick = () => {
document.querySelector('canvas').height = 300;
}
canvas {
background-color: blue;
display: block; /* added */
}
#grid {
background-color: black;
display: grid;
grid-template-rows: 1fr auto;
width: 400px;
height: 400px;
}
#canvas-area {
grid-row: 1;
background-color: red;
min-height: 0; /* added */
overflow: auto; /* added */
}
#animator {
grid-row: 2;
height: 200px;
}
<div id="grid">
<div id="canvas-area">
<canvas/>
</div>
<div id="animator"></div>
</div>
<button>Change Canvas Height</button>
Related
Im having issues trying to create a sticky sidebar. On mobile the content just needs to flow within its container, then on desktop that div needs to break out into a sticky sidebar on the right, while the content flows on the left side as normal:
http://jsfiddle.net/sace510n/
Think its causing issues because the div for the sidebar is in the middle of each block.
.a {
position: sticky;
top: 0;
right: 0;
}
}
Any ideas would be greatly appreciated, thanks
Grid is the way to go here imho. Just create a new grid with 2 columns for your desktop inside your media query then set grid-column for the grey items to the left and the red one to the right. Then use position: sticky to, er, make it sticky.
The code should be self-explanatory but if not just drop me a comment on and I'll explain.
Edited: If each element is a different size, and the right-hand element is bigger than the first left-hand element then the gaps may look uneven. To solve this use a grid-row span on the .b class rule and choose a span that's big enough to keep the gaps even. Unfortunately grid-row: 1/-1 doesn't work on implicit grids.
body {
background: #20262e;
padding: 20px;
font-family: Helvetica;
}
.content {
display: grid;
gap: 1rem;
width: 100%;
max-width: 800px;
margin: 0 auto;
outline: 1px solid lime;
}
.a,
.b {
padding: 15px;
width: 200px;
height: 100px;
margin: 0 auto;
display: block;
}
.a {
background: grey;
}
.b {
background: red;
height: fit-content; /* added this during edit */
}
#media (min-width: 768px) {
.content {
grid-template-columns: repeat(2, 1fr);
}
.a {
grid-column: 1/2;
}
.b {
position: sticky;
top: 0;
grid-column: 2/3;
grid-row: 1/ span 3; /* <- choose a number to give the RHS grid enough space so the gaps of the LHS items don't grow */
}
}
.h0 {
height: 2.5rem;
}
.h1 {
height: 10rem;
}
.h2 {
height: 13rem;
}
.h3 {
height: 4rem;
}
<div class="content">
<div class="a h0">title1</div>
<div class="a">title2</div>
<div class="a">title3</div>
<div class="a">title4</div>
<div class="a h1">title5</div>
<div class="a h1">title6</div>
<div class="a">title7</div>
<div class="a h2">title8</div>
<div class="b">here on mobile, sticky sidebar on desktop <br/>title<br />title<br />title<br />title<br />title<br />title<br /></div>
<div class="a h1">title9</div>
<div class="a h3">title10</div>
</div>
This question already has an answer here:
Why does minmax(0, 1fr) work for long elements while 1fr doesn't?
(1 answer)
Closed last year.
Problem: I am having a problem with sizing images inside css grid column/rows. I essentially object-fit: contain the imagesinside their individual cells.
The image in "SPOT 4" is not filling the given space
If you uncomment the image in "SPOT 1", it will cover the entire grid and is not confined to its own css grid cell.
I have tried setting max-width, object-fit and others on the video level and .channel-container level with no success.
Background: The .parent-trap css class is just an example height/width. This will vary, it may be the entire browser window, or it may be small so I cannot depend on any specific min/max dimensions. There are also other .display4 in the full version that sometimes shows a single video that fills the whole grid, side by side that only shows 2 at a time etc, so any specific dimensions also tend to break individual .display*
html,
body {
border: 0;
margin: 0;
height: 100%;
}
.parent-trap {
height: 540px;
width: 960px;
}
/* container for player */
.video-player {
display: flex;
flex-direction: column;
height: 100%;
width: 100%;
max-height: 100%;
max-width: 100%;
min-height: 100%;
min-width: 100%;
}
/* container for plaback control bar */
.container-controls {
height: 50px;
background-color: red;
}
/* contains all the .channel-container s */
.channel-layout-container {
display: grid;
background: #000;
background-color: blue;
flex: 1;
}
/****
**** FIX HERE
****/
.channel-container {}
img {}
/** THERE ARE OTHER DYNAMIC LAYOUTS, ISSUE IS SAME ON ALL */
/** display4 **/
.channel-layout-container.display4 {
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;
}
.channel-layout-container.display4 .channel-container:nth-child(n+5) {
flex: none;
display: none;
}
<!-- try restricting various sizes -->
<div class="parent-trap">
<!-- the classcommes that need to be transferred back over-->
<div class="video-player">
<div class="channel-layout-container display4">
<div class="channel-container" style="background-color: khaki;">
<!-- <img src="https://w.wallhaven.cc/full/3z/wallhaven-3zgz2y.png" />-->
</div>
<div class="channel-container" style="background-color: lavender;">
SPOT 2
</div>
<div class="channel-container" style="background-color: lightcoral;">
SPOT 3
</div>
<div class="channel-container" style="background-color: lightseagreen;">
<img src="https://www.google.com/favicon.ico" />
</div>
</div>
<div class="container-controls">
common controls and other info goes here
</div>
</div>
</div>
Your issue results from your grid template definition.
Replace 1fr 1fr with repeat(2, minmax(0, 1fr)).
The reason for your problem is that 1fr effectively means minmax(auto, 1fr). minmax works such that if the first argument is greater than the second, the whole minmax expression is replaced by the first argument, so your whole definition becomes
grid-template-columns: auto auto;
grid-template-rows: auto auto;
Setting minmax(0, 1fr) prevents this and effectively sets what you did by setting min-width/-height to 0.
I ended up needing 3 things, I'm not entirely sure what the min-width/height: 0 are doing to fix my issue but it works
.channel-layout-container {
min-height: 0; /* NEW */
min-width: 0; /* NEW; needed for Firefox */
}
.channel-container {
min-height: 0; /* NEW */
min-width: 0; /* NEW; needed for Firefox */
}
img {
display:block;
width :100%;
height:100%;
object-fit:cover;
}
html,
body {
border: 0;
margin: 0;
height: 100%;
}
.parent-trap {
height: 540px;
width: 960px;
}
/* container for player */
.video-player {
display: flex;
flex-direction: column;
height: 100%;
width: 100%;
max-height: 100%;
max-width: 100%;
min-height: 100%;
min-width: 100%;
}
/* container for plaback control bar */
.container-controls {
height: 50px;
min-height: 50px;
max-height: 50px;
background-color: red;
}
/* contains all the .channel-container s */
.channel-layout-container {
display: grid;
background: #000;
background-color: blue;
flex: 1;
min-height: 0; /* NEW */
min-width: 0; /* NEW; needed for Firefox */
}
/****
**** FIX HERE
****/
.channel-container {
min-height: 0; /* NEW */
min-width: 0; /* NEW; needed for Firefox */
}
img {
display:block;
width :100%;
height:100%;
object-fit:cover;
}
/** THERE ARE OTHER DYNAMIC LAYOUTS, ISSUE IS SAME ON ALL */
/** display4 **/
.channel-layout-container.display4 {
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;
}
.channel-layout-container.display4 .channel-container:nth-child(n+5) {
flex: none;
display: none;
}
<div class="parent-trap">
<!-- the classcommes that need to be transferred back over-->
<div class="video-player">
<div class="channel-layout-container display4">
<div class="channel-container" style="background-color: khaki;">
<img src="https://w.wallhaven.cc/full/3z/wallhaven-3zgz2y.png" />
</div>
<div class="channel-container" style="background-color: lavender;">
SPOT 2
</div>
<div class="channel-container" style="background-color: lightcoral;">
SPOT 3
</div>
<div class="channel-container" style="background-color: lightseagreen;">
<img src="https://www.google.com/favicon.ico" />
</div>
</div>
<div class="container-controls">
common controls and other info goes here
</div>
</div>
</div>
You can see now that changing .parent-trap dimensions keep the proper proportions , control bar is always available and just the displays adjust as necessary.
I am trying to insert scrollable content into a CSS grid layout, without the grid layout slot containing the scrollable content automatically growing in an attempt to accomodate that content.
I would like the size of the grid item to be the same as it would have been without the scrollable content.
I have found that setting the height of a container for the scrollable content to a fixed value gives the desired results, but I don't know in advance what that value should be. Perhaps it's possible to calculate the value in JavaScript, but I would prefer not to unless it were the only way. I want it to be based on the space that would have been available had that content not existed.
In the example below, when you click the "Large amount of output" button, the height of the #right1 div grows from 300px to a larger value. I would like the height of #right1 to be unchanged when clicking this button. I essentially want to make it behave as if the height of #output_container were set to a fixed value. But I don't want to manually specify the fixed value, because I want it to use all of the available space. The height of #output_container is currently set to 100%. That makes it the correct size, unless the unless its child div (#output) forces it to grow. I want to prevent this type of growth, because that content is scrollable. It's not necessary to make the #output_container larger to see that content.
I've tried using grid and flex layouts inside of #right1 to specify that #output_container should use the remaining vertical space in #right1 under everything else. However, #output_container still grows based on the #output div inside of #output_container and I don't want it to do that.
function showSize(selector) {
const a = document.querySelector(selector);
const p = a.querySelector('p');
p.textContent = `${getComputedStyle(a).width} x ${getComputedStyle(a).height}`;
}
function showSizes() {
showSize('#left');
showSize('#right1');
showSize('#right2');
window.setTimeout(showSizes, 100);
}
function writeOutput(lines) {
const output = document.querySelector('#output');
let text = '';
for (let i = 0; i < lines; i++) {
for (let j = 65; j < 91; j++) {
text += String.fromCharCode(j);
}
text += "\n";
}
output.textContent = text;
output.scrollTop = output.scrollHeight;
}
document.querySelector('#small').addEventListener('click', () => writeOutput(5));
document.querySelector('#large').addEventListener('click', () => writeOutput(50));
writeOutput(5);
showSizes();
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
#output_container {
/* Setting the height to 100% makes it the right size, unless its child div forces it to grow.
I want to prevent this type of growth, because the child content is scrollable.
*/
height: 100%;
/* Setting the height to a fixed size works, but I don't know in advance what the size should be in order for the Output panel to be be size that it would have been if this content were not there. */
/* height: 170px; */
background: lightseagreen;
}
#output {
background-color: hsl(0, 0%, 83%);
min-height: 50px;
max-height: 100%;
padding: 0.5em;
overflow: auto;
}
.pre {
white-space: pre;
font-family: monospace;
}
.pre:after {
/* Allows user to see a trailing line break. */
content: '';
}
#grid {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;
grid-template-areas:
"left right1"
"left right2";
}
#left {
grid-area: left;
background: lightskyblue;
display: flex;
flex-direction: column;
// min-height: 800px;
}
#grid > div {
padding: 10px;
overflow: hidden;
}
#right1 {
grid-area: right1;
background: seagreen;
min-height: 300px;
display: grid;
grid-template-rows: auto auto 1fr;
}
#right2 {
grid-area: right2;
background: lightsalmon;
min-height: 300px;
}
h1 {
margin: 0.5rem 0;
}
button {
margin: 0.25rem;
}
<div id="grid">
<div id="left">
<p></p>
<button id="small">Small amount of output</button>
<button id="large">Large amount of output</button>
</div>
<div id="right1">
<p></p>
<h1>Output</h1>
<div id="output_container">
<div id="output" class="pre"></div>
</div>
</div>
<div id="right2">
<p></p>
</div>
</div>
The solution was to add position: relative; to the container that I didn't want to grow (#output_container) and position: absolute; width: 100%; to its child (#output), whose content was causing the growth of the parent container.
function showSize(selector) {
const a = document.querySelector(selector);
const p = a.querySelector('p');
p.textContent = `${getComputedStyle(a).width} x ${getComputedStyle(a).height}`;
}
function showSizes() {
showSize('#left');
showSize('#right1');
showSize('#right2');
window.setTimeout(showSizes, 100);
}
function writeOutput(lines) {
const output = document.querySelector('#output');
let text = '';
for (let i = 0; i < lines; i++) {
for (let j = 65; j < 91; j++) {
text += String.fromCharCode(j);
}
text += "\n";
}
output.textContent = text;
output.scrollTop = output.scrollHeight;
}
document.querySelector('#small').addEventListener('click', () => writeOutput(5));
document.querySelector('#large').addEventListener('click', () => writeOutput(50));
writeOutput(5);
showSizes();
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
#output_container {
/* Setting the height to 100% makes it the right size, unless its child div forces it to grow.
I want to prevent this type of growth, because the child content is scrollable.
*/
height: 100%;
/* Setting the height to a fixed size works, but I don't know in advance what the size should be in order for the Output panel to be be size that it would have been if this content were not there. */
/* height: 170px; */
background: lightseagreen;
position: relative;
}
#output {
position: absolute;
width: 100%;
background-color: hsl(0, 0%, 83%);
min-height: 50px;
max-height: 100%;
padding: 0.5em;
overflow: auto;
}
.pre {
white-space: pre;
font-family: monospace;
}
.pre:after {
/* Allows user to see a trailing line break. */
content: '';
}
#grid {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;
grid-template-areas:
"left right1"
"left right2";
}
#left {
grid-area: left;
background: lightskyblue;
display: flex;
flex-direction: column;
// min-height: 800px;
}
#grid > div {
padding: 10px;
overflow: hidden;
}
#right1 {
grid-area: right1;
background: seagreen;
min-height: 300px;
display: grid;
grid-template-rows: auto auto 1fr;
}
#right2 {
grid-area: right2;
background: lightsalmon;
min-height: 300px;
}
h1 {
margin: 0.5rem 0;
}
button {
margin: 0.25rem;
}
<div id="grid">
<div id="left">
<p></p>
<button id="small">Small amount of output</button>
<button id="large">Large amount of output</button>
</div>
<div id="right1">
<p></p>
<h1>Output</h1>
<div id="output_container">
<div id="output" class="pre"></div>
</div>
</div>
<div id="right2">
<p></p>
</div>
</div>
I have a css grid with a single column and two rows.
I want the first row to expand when there is space and to scroll when there is no space.
I want the second row to remain at the bottom of the div.
I have tried using display: flex; in the first row.
HTML:
<div class="parent">
<span class="top">my<br>long<br>long<br>long<br>content</span>
<span class="bottom">always visible</span>
</div>
CSS:
body {
overflow-y: hidden;
}
.parent {
display: grid;
grid-template-columns: auto;
grid-template-rows: 1fr 0fr;
}
.top {
overflow-y: scroll;
display: flex;
flex-direction: column;
}
span {
border: solid;
}
https://jsfiddle.net/9re86f2a/
I expect the first row to scroll when there is no space, but it actually remains the same size.
I expect the first row to expand when there is space, but it actually remains the same size.
I would use the flex model for this kind of behavior even if grid does it fine ;)
html * {
box-sizing:border-box;
padding:0.25em;
margin:0;
}
body {
height:100vh;
}
.parent {
display: flex;
flex-direction: column;
max-height: 100%;
overflow: hidden;
}
.top {
flex-grow: 1;
overflow: auto;
/* style aside */
background:lightblue;
margin:2px;/* or 0 */
border:solid;
}
.bottom {
flex-shrink: 0;
/* style aside */
background:tomato;
margin:2px;/* or 0 */
border:solid;
}
/* demo purpose */
.top .demo {
display: block;
max-height: 0;
overflow: hidden;
transition: 1.5s;
}
.top:hover .demo {
max-height: 300vh;
}
<div class="parent">
<span class="top"><b>Hover me to show my long content</b>
<span class="demo"><br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content</span>
</span>
<span class="bottom">always visible</span>
</div>
There's nothing in your code that triggers an overflow condition.
In order for content to overflow, it needs to exceed a width or height limitation (e.g. height: 300px), which then triggers the scrollbar.
From MDN:
In order for overflow to have an effect, the block-level container must have either a set height (height or max-height) or white-space set to nowrap.
In other words, without a fixed height, you won't get the vertical scrollbar... in Chrome! Ironically, however, in Firefox, a product of MDN, and Edge, the MDN rule above doesn't apply, and your layout works just fine.
.parent {
display: grid;
grid-template-columns: auto;
grid-template-rows: 1fr 0fr;
grid-gap: 2px;
background-color: black;
height: 100vh;
}
.top {
overflow-y: auto;
}
span {
background-color: white;
}
body {
margin: 0;
}
<div class="parent">
<span class="top">my<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content<br>long<br>long<br>long<br>content</span>
<span class="bottom">always visible</span>
</div>
jsFiddle demo
Note on browser rendering differences: I can only speculate as to why Firefox and Edge render a scrollbar on a block-level container that doesn't have a defined height or max-height, as specified by MDN (see above). They could be engaging in an intervention or may have a different interpretation of the specification than the MDN contributors.
I'm using the following grid layout:
grid-template-columns: 10em 1fr 10em;
grid-template-rows: 2em 1fr 2em;
To create a centered area that fills most of the screen while leaving some padding around it. Inside this 1fr x 1fr grid area is a pane div which contains an editor div which contains a content div.
The content div can be any height, and the editor div has overflow: scroll set. My problem is that instead of pane staying the same size and editor handling the overflow, pane grows and causes the whole page to scroll.
I can keep pane from growing by setting its overflow: scroll, but this causes the editor itself to scroll, rather than its content. This is unacceptable because the editor has buttons which must always be on screen.
Is there a way, within grid layout, to allow this functionality? I originally had it working with a flex layout, where the pane div was a single item within a 100% x 100% flexbox. I switched to grid to allow me to easily resize side-menus, so implementing this without grid is not preferable.
Also, multi-browser support would be amazing, but my target browser is Chrome.
Here's a jsfiddle with my reproducing my problem.
body, html {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
#site {
width: 100%;
height: 100%;
background-color: #000;
display: grid;
grid-template-rows: 10em 1fr 10em;
grid-template-columns: 2em 1fr 2em;
grid-template-areas:
'top top top'
'lpn mid rpn'
'bot bot bot';
}
#pane {
grid-area: mid;
height: 100%;
width: 100%;
background-color: #f0f;
}
#editor {
display: relative;
overflow: scroll;
}
#content {
height: 2000px;
}
<div id='site'>
<div id='pane'>
<div id='editor'>
<div id='content'>
</div>
</div>
</div>
</div>
min-width: auto / min-height: auto
Generally speaking, a grid item cannot be smaller than its content. The default minimum size of grid items is min-width: auto and min-height: auto.
This often causes grid items to overflow their grid areas or grid containers. It also prevents scrollbars from rendering on the items, since an overflow condition can't be triggered (the grid item just keeps expanding).
To override this default (and allow grid items to shrink past their content size) you can use min-width: 0, min-height: 0 or overflow with any value other than visible.
This behavior, with references to official documentation, is explained in this post:
Prevent content from expanding grid items
1fr
Another thing to note is that 1fr means minmax(auto, 1fr). This means, again, that the track to which it is applied cannot shrink below the content size (i.e., the min value in the minmax() function is auto, meaning content-based).
Therefore, to override this setting, use minmax(0, 1fr) instead of 1fr.
More details here: https://github.com/w3c/csswg-drafts/issues/1777
revised demo (tested in Chrome, Firefox and Edge)
body, html {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
#site {
width: 100%;
height: 100%;
background-color: #000;
display: grid;
/* grid-template-rows: 10em 1fr 10em; */
grid-template-rows: 10em minmax(0, 1fr) 10em; /* new */
grid-template-columns: 2em 1fr 2em;
grid-template-areas:
'top top top'
'lpn mid rpn'
'bot bot bot';
}
#pane {
grid-area: mid;
height: 100%;
width: 100%;
background-color: #f0f;
overflow: auto; /* new */
}
#editor {
/* display: relative; */
/* overflow: scroll; */
}
#content {
height: 2000px;
}
<div id='site'>
<div id='pane'>
<div id='editor'>
<div id='content'></div>
</div>
</div>
</div>
jsFiddle demo
Not 100% sure if this is what you're asking. I added a wrapper to content to make it scrollable, and set a vh height on it, which you could adjust.
#content-scroll {
height: 40vh;
overflow: scroll;
}
#content {
height: 2000px;
}
<div id='site'>
<div id='pane'>
<div id='editor'>
<div id='content-scroll'>
<div id='content'>
</div>
</div>
</div>
</div>
</div>
https://jsfiddle.net/16owL8x0/