0

I have a 2x3 grid, consisting of 1 2x1 and 4 1x1 elements. I want to show the whole 2x1 cell, and make the 1x1 cells y-scrollable for anything past the min-content height of the 2x1 cell. That is to say, I want the whole grid to be the minimum height that it takes for the 2x1 cell not to overflow. Is there any way I can achieve this? Currently, I am using grid.

:not(html, body, .container) {
  padding: .5em;
  border: 1px solid goldenrod;
  border-radius: .25em;
}

.container { 
  display: grid;
  grid:
    "chart details-a details-b" 200px
    "chart details-c details-d" 200px
    / 1fr 2fr 2fr;
  gap: .5em;
}

.chart {
  grid-area: chart;
}

[class^=details] {
  overflow-y: auto;
}

.details-a {
  grid-area: details-a;
}

.details-b {
  grid-area: details-b;
}

.details-c {
  grid-area: details-c;
}

.details-d {
  grid-area: details-d;
}
<div class="container">
  <div class="chart">
    this
    <br>
    thing
    <br>
    here
    <br>
    must
    <br>
    be
    <br>
    a
    <br>
    chart
    <br>
    but
    <br>
    is
    <br>
    it
    <br>
    a
    <br>
    chart
  </div>
  <div class="details-a">
    We need to crystallize a plan business impact strategic high-level 30,000 ft view our competitors are jumping the shark. Gain traction UI, but game-plan. Can you run this by clearance? hot johnny coming through . Canatics exploratory investigation data masking 360 degree content marketing pool but conversational content so streamline you better eat a reality sandwich before you walk back in that boardroom. Unlock meaningful moments of relaxation red flag cta yet message the initiative, and blue sky thinking we can't hear you . When does this sunset? pulling teeth a better understanding of usage can aid in prioritizing future efforts onward and upward, productize the deliverables and focus on the bottom line we need to make the new version clean and sexy. Agile commitment to the cause yet closer to the metal so pipeline, yet land the plane for quick win, but shoot me an email. In an ideal world take five, punch the tree, and come back in here with a clear head we want to see more charts you gotta smoke test your hypothesis or you must be muted for paddle on both sides. Service as core &innovations as power makes our brand herding cats, so quick win, for high-level, for horsehead offer. Good optics increase the pipelines. We need a paradigm shift. This is not the hill i want to die on. We need to make the new version clean and sexy circle back but due diligence best practices i'm sorry i replied to your emails after only three weeks, but can the site go live tomorrow anyway? and 360 degree content marketing pool. Have bandwidth deploy to production but hit the ground running nor 60% to 30% is a lot of persent nor if you're not hurting you're not winning business impact and poop. Currying favour let's take this conversation offline nor that is a good problem to have this is a no-brainer anti-pattern. Have bandwidth workflow ecosystem yet drill down, net net.
  </div>
  <div class="details-b">
    I'm baby knausgaard synth farm-to-table, squid paleo woke slow-carb four loko street art cronut iPhone butcher humblebrag direct trade hella. Salvia coloring book cornhole cloud bread migas glossier microdosing leggings cray live-edge distillery yuccie ennui swag. Pinterest subway tile actually fixie, lo-fi prism poke taxidermy tofu. Helvetica activated charcoal roof party shaman wayfarers drinking vinegar stumptown tacos man braid small batch actually direct trade. Migas gentrify tumeric salvia gluten-free slow-carb swag. Raw denim umami authentic thundercats fanny pack, locavore four dollar toast polaroid vexillologist quinoa lo-fi poutine. Fixie biodiesel everyday carry YOLO humblebrag. Bushwick offal brunch green juice, messenger bag tattooed freegan truffaut iceland banjo. Bitters everyday carry typewriter letterpress cardigan franzen. Hexagon cray lomo stumptown keytar, normcore drinking vinegar helvetica polaroid 8-bit VHS mlkshk shabby chic. Slow-carb stumptown man bun copper mug, mlkshk vinyl succulents poutine mixtape health goth fanny pack cornhole roof party. IPhone occupy put a bird on it kale chips, tacos artisan salvia cold-pressed marfa selvage tote bag. Messenger bag small batch affogato kickstarter, pork belly adaptogen drinking vinegar vinyl bicycle rights truffaut. Meditation lumbersexual sustainable wolf, semiotics YOLO chartreuse. Seitan fixie venmo truffaut gluten-free master cleanse chambray raclette prism, cliche af DIY cray fanny pack. Single-origin coffee 3 wolf moon salvia, shoreditch vegan put a bird on it kogi leggings sriracha retro yuccie man bun green juice live-edge cred. Ethical raclette sustainable chambray you probably haven't heard of them squid.
  </div>
  <div class="details-c">
    Okay, hello, it's the Martian. Young money. Excuse my charisma, vodka with a spritzer. So misunderstood but what's the world without enigma? I lost my mind, it's somewhere out there stranded. I need a Winn-Dixie bag full of money right now to the VIP section. Just talked to moms, told her she the sweetest. Talking to myself because I am my own consultant. Paper chasin', tell that paper "Look, I'm right behind ya." Real G's move in silence like lasagna. People say I'm borderline crazy, sorta kinda. Got the Maserati dancing on the bridge. You pop'em cause we pop'em like Orville Redenbacher. But what should I scream for? This is my theme park. You're a goon but what's a goon to a goblin? I don't owe you like two vowels. Even Gwen Stefani said she couldn't doubt me. Met a female dragon, had a fire conversation. Approving million-dollar deals from my iPhone. Flyer than Beetlejuice, Beetlejuice, Beetlejuice. I got summer hating on me cause I'm hotter than the sun. Got Spring hating on me cause I ain't ever sprung. I parallel park in that red-and-yellow thing, old school Atlanta Hawk. And my chain Toucan Sam, that tropical colors, you can't match that, gotta be abstract. Quick Draw McGraw, I went to art school. I'm about to go Andre the Giant. Gotta handful of stacks, better grab an umbrella. I'm counting all day like a clock on the wall. I'm too clean for the choir.
  </div>
  <div class="details-d">
    Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro. De carne lumbering animata corpora quaeritis. Summus brains sit​​, morbo vel maleficia? De apocalypsi gorger omero undead survivor dictum mauris. Hi mindless mortuis soulless creaturas, imo evil stalking monstra adventus resi dentevil vultus comedat cerebella viventium. Qui animated corpse, cricket bat max brucks terribilem incessu zomby. The voodoo sacerdos flesh eater, suscitat mortuos comedere carnem virus. Zonbi tattered for solum oculi eorum defunctis go lum cerebro. Nescio brains an Undead zombies. Sicut malus putrid voodoo horror. Nigh tofth eliv ingdead.
  </div>
</div>
What I have:
______
|@|a|b|
|@|a|b|
| |c|d|
|_|c|d|
What I want:
______
|@|a|b|
|@|c|d|
Ders
  • 1,068
  • 13
  • 16
  • On my end it looks like what you want, unless I'm misunderstanding something. – pso Mar 18 '22 at 04:40
  • See [A Haworth's answer](https://stackoverflow.com/a/71523062/9890027) for an example of what I had in mind. – Ders Mar 18 '22 at 06:24

2 Answers2

1

Given that HTML structure you can make your own 'grid' by first ensuring container has the height of chart by positioning that relative within container but then positioning the other elements absolute.

Positions and dimensions are calculated involving a CSS variable which holds the desired gap between elements.

* {
  margin: 0;
}

 :not(html, body, .container) {
  padding: .5em;
  border: 1px solid goldenrod;
  border-radius: .25em;
  box-sizing: border-box;
}

.container {
  --gap: .5em;
  --hg: calc(var(--gap) / 2);
  position: relative;
  display: inline-block;
  width: 100vw;
}

.container>* {
  margin: 0;
}

.chart {
  grid-area: chart;
  width: calc(20% - var(--hg));
}

[class^=details] {
  overflow-y: auto;
  position: absolute;
  height: calc(50% - var(--hg));
  width: calc(40% - (var(--hg) * 3 / 2));
  display: inline-block;
  overflow: auto;
}

.details-a {
  top: 0;
  left: calc(20% + var(--hg));
}

.details-b {
  top: 0;
  right: 0;
}

.details-c {
  bottom: 0;
  left: calc(20% + var(--hg));
}

.details-d {
  bottom: 0;
  right: 0;
}
<div class="container">
  <div class="chart">
    this
    <br> thing
    <br> here
    <br> must
    <br> be
    <br> a
    <br> chart
    <br> but
    <br> is
    <br> it
    <br> a
    <br> chart
  </div>
  <div class="details-a">
    We need to crystallize a plan business impact strategic high-level 30,000 ft view our competitors are jumping the shark. Gain traction UI, but game-plan. Can you run this by clearance? hot johnny coming through . Canatics exploratory investigation data
    masking 360 degree content marketing pool but conversational content so streamline you better eat a reality sandwich before you walk back in that boardroom. Unlock meaningful moments of relaxation red flag cta yet message the initiative, and blue
    sky thinking we can't hear you . When does this sunset? pulling teeth a better understanding of usage can aid in prioritizing future efforts onward and upward, productize the deliverables and focus on the bottom line we need to make the new version
    clean and sexy. Agile commitment to the cause yet closer to the metal so pipeline, yet land the plane for quick win, but shoot me an email. In an ideal world take five, punch the tree, and come back in here with a clear head we want to see more charts
    you gotta smoke test your hypothesis or you must be muted for paddle on both sides. Service as core &innovations as power makes our brand herding cats, so quick win, for high-level, for horsehead offer. Good optics increase the pipelines. We need
    a paradigm shift. This is not the hill i want to die on. We need to make the new version clean and sexy circle back but due diligence best practices i'm sorry i replied to your emails after only three weeks, but can the site go live tomorrow anyway?
    and 360 degree content marketing pool. Have bandwidth deploy to production but hit the ground running nor 60% to 30% is a lot of persent nor if you're not hurting you're not winning business impact and poop. Currying favour let's take this conversation
    offline nor that is a good problem to have this is a no-brainer anti-pattern. Have bandwidth workflow ecosystem yet drill down, net net.
  </div>
  <div class="details-b">
    I'm baby knausgaard synth farm-to-table, squid paleo woke slow-carb four loko street art cronut iPhone butcher humblebrag direct trade hella. Salvia coloring book cornhole cloud bread migas glossier microdosing leggings cray live-edge distillery yuccie
    ennui swag. Pinterest subway tile actually fixie, lo-fi prism poke taxidermy tofu. Helvetica activated charcoal roof party shaman wayfarers drinking vinegar stumptown tacos man braid small batch actually direct trade. Migas gentrify tumeric salvia
    gluten-free slow-carb swag. Raw denim umami authentic thundercats fanny pack, locavore four dollar toast polaroid vexillologist quinoa lo-fi poutine. Fixie biodiesel everyday carry YOLO humblebrag. Bushwick offal brunch green juice, messenger bag
    tattooed freegan truffaut iceland banjo. Bitters everyday carry typewriter letterpress cardigan franzen. Hexagon cray lomo stumptown keytar, normcore drinking vinegar helvetica polaroid 8-bit VHS mlkshk shabby chic. Slow-carb stumptown man bun copper
    mug, mlkshk vinyl succulents poutine mixtape health goth fanny pack cornhole roof party. IPhone occupy put a bird on it kale chips, tacos artisan salvia cold-pressed marfa selvage tote bag. Messenger bag small batch affogato kickstarter, pork belly
    adaptogen drinking vinegar vinyl bicycle rights truffaut. Meditation lumbersexual sustainable wolf, semiotics YOLO chartreuse. Seitan fixie venmo truffaut gluten-free master cleanse chambray raclette prism, cliche af DIY cray fanny pack. Single-origin
    coffee 3 wolf moon salvia, shoreditch vegan put a bird on it kogi leggings sriracha retro yuccie man bun green juice live-edge cred. Ethical raclette sustainable chambray you probably haven't heard of them squid.
  </div>
  <div class="details-c">
    Okay, hello, it's the Martian. Young money. Excuse my charisma, vodka with a spritzer. So misunderstood but what's the world without enigma? I lost my mind, it's somewhere out there stranded. I need a Winn-Dixie bag full of money right now to the VIP
    section. Just talked to moms, told her she the sweetest. Talking to myself because I am my own consultant. Paper chasin', tell that paper "Look, I'm right behind ya." Real G's move in silence like lasagna. People say I'm borderline crazy, sorta kinda.
    Got the Maserati dancing on the bridge. You pop'em cause we pop'em like Orville Redenbacher. But what should I scream for? This is my theme park. You're a goon but what's a goon to a goblin? I don't owe you like two vowels. Even Gwen Stefani said
    she couldn't doubt me. Met a female dragon, had a fire conversation. Approving million-dollar deals from my iPhone. Flyer than Beetlejuice, Beetlejuice, Beetlejuice. I got summer hating on me cause I'm hotter than the sun. Got Spring hating on me
    cause I ain't ever sprung. I parallel park in that red-and-yellow thing, old school Atlanta Hawk. And my chain Toucan Sam, that tropical colors, you can't match that, gotta be abstract. Quick Draw McGraw, I went to art school. I'm about to go Andre
    the Giant. Gotta handful of stacks, better grab an umbrella. I'm counting all day like a clock on the wall. I'm too clean for the choir.
  </div>
  <div class="details-d">
    Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro. De carne lumbering animata corpora quaeritis. Summus brains sit​​, morbo vel maleficia? De apocalypsi gorger omero undead survivor dictum mauris. Hi mindless mortuis soulless creaturas,
    imo evil stalking monstra adventus resi dentevil vultus comedat cerebella viventium. Qui animated corpse, cricket bat max brucks terribilem incessu zomby. The voodoo sacerdos flesh eater, suscitat mortuos comedere carnem virus. Zonbi tattered for
    solum oculi eorum defunctis go lum cerebro. Nescio brains an Undead zombies. Sicut malus putrid voodoo horror. Nigh tofth eliv ingdead.
  </div>
</div>
A Haworth
  • 30,908
  • 4
  • 11
  • 14
  • This is a great example of what I had in mind. But, I was hoping to do it without the custom code, which inherently makes it much less maintainable. This is illustrated by the horizontal scroll. – Ders Mar 18 '22 at 06:20
  • I am really starting to think this isn't possible with grid unless I start setting heights somewhere. – Ders Mar 18 '22 at 06:21
  • Hi, could you describe what the problem is with 'horizontal scroll'? I wasn't aware I'd introduced it but obvioiusly must have done. I'm not sure I take your point about maintainability. The gap is changed as easily as on the original and if you are likely to want to change from 1fr 2fr 2fr for example then parameterise that 20% as well. – A Haworth Mar 18 '22 at 06:24
  • 1
    Yes agree with your comment on height. It's necessary to get the height from the chart first I think and then I don't know how to persuade grid that it mustn't adjust for the other elements. – A Haworth Mar 18 '22 at 06:26
  • I've checked again on horizontal scroll and don't see any when I run the snippet. – A Haworth Mar 18 '22 at 06:29
  • FYI I am on Windows (Windows-style scroll bars). Perhaps if you are on a Mac the scrolling is different, but it should be platform-independent. – Ders Mar 18 '22 at 06:30
  • 1
    I'm on Window10 - not seeing any scroll bars (other than the ones you want). Using Edge. – A Haworth Mar 18 '22 at 06:31
  • Edit: I turned on responsive design mode in devtools and bumped up to the 4k TV and there was none - so something is there with the viewport / responsiveness / platform combination - I am on a smaller laptop. – Ders Mar 18 '22 at 06:33
  • OK, seen it when make the height smaller than the 'chart' height - it's because of the windows vertical scrollbar which has to be introduced to allow the user to see the whole chart. What do you want to happen when the device can't accomodate all of the chart vertically? – A Haworth Mar 18 '22 at 06:39
  • You can set max-height of the chart element to 100vh and allow scrolling on that, but I suspect your problem is that you want chart to definitely show completely however small the viewport? (as opposed to scrolling just text) What is chart in real life, is it an image? – A Haworth Mar 18 '22 at 06:45
-1

You can make use of grid-row and grid-column properties in relation to your initial template for columns.

.wrapper {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
}
.wrapper > .special:nth-child(1) {
  grid-column: 1;
  grid-row: 1;
}
.wrapper > .special:nth-child(2) {
  grid-column: 1;
  grid-row: 2;
}
    <div class="wrapper">
      <div class="special">@</div>
      <div class="special">@</div>
      <div class="a">A</div>
      <div class="b">B</div>
      <div class="c">C</div>
      <div class="d">D</div>
    </div>
Radu
  • 7
  • 3