2

Is there a way to force a grid section to match the height of another column? I have a video player and a long list of videos for the user to choose from. The list currently has the overflow-y: scroll property and a max height to fill the total grid area. But, because the video player has a dynamic height as well there ends up being a gap.

Here's what I'm going for:

Desired layout

I want the red section to max out where the yellow section ends. I'm currently trying to use a display: grid layout, but I'm open to different suggestions.

4
  • share your code so we can see what you have done and suggest or advise from there. Commented Jul 1, 2021 at 21:18
  • 2
    You can't use CSS-Grid without using specific heights here. If you had two actual column wrappers then this is possible, Commented Jul 1, 2021 at 21:54
  • 1
    stackoverflow.com/questions/34194042/… Commented Jul 1, 2021 at 21:59
  • 1
    looks to me like a typical grid-layout,. no need to set an explicit height, height will com from the contents themselves, except for the list part that we have to remove from the height calculation via .. height:0 (right an height is needed) . live example : codepen.io/gc-nomade/pen/PomPbEM Is that what you look for ? Commented Jul 3, 2021 at 11:09

1 Answer 1

7

(from earlier comment) Here is a grid example excluding the list part from height calculation.

section {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto 1fr auto;
  gap: 1em;
  margin: auto;
  max-width: 1200px; 
}

#box1 {
  grid-row: 1;
  grid-column: 1;
  background: #90EE90;
  padding: 1em;
}

#box2 {
  grid-column: 1;
  grid-row: 2 / span 2;
  height: 0;/* remove it from heigt calculation*/
  min-height: 100%;/* give it a min-height to match rows's height */
  overflow: auto;
  background: #FF6347;
}

#box3 {
  grid-column: 2;
  grid-row: 1 / span 2;
  background: #6495ED;
  width: 100%;
}

#box4 {
  grid-column: 2;
  grid-row: 3;
  background: #FFFF00;
  text-align: center;
  padding: 1em;
}
<section>
  <div id="box1"> <input placeholder="filter"></div>
  <div id="box2">
    <ul>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
      <li>list-itel</li>
    </ul>
  </div>
  <video id="box3" controls>

    <source src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm"
            type="video/webm">

    <source src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4"
            type="video/mp4">

    Sorry, your browser doesn't support embedded videos.
</video>
  <div id="box4"><button>button</button></div>
</section>

Sign up to request clarification or add additional context in comments.

1 Comment

So height: 0, min-height: 100% is the trick here. Odd hack but can't argue with results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.