2 column layout with 1 aspect ratio container and a full height div

NickW

I'm trying to create a 2 column layout, with one column 2/3rds wide, and the second 1/3rd.

The first column should be taken up by a video container that maintains an aspect ratio of 4:3. I think I've done that correctly by setting the padding of the video container to 75%.

I'd like the 3rd column to contain a div that expands to the full height of the row. It doesn't seem able to.

I just wanted to ask if this was because the column layout gains its height from the video container (which in turn is based on it's width)? Or have I just overlooked something simple? I'd like to stop randomly adding 'height: 100%' to everything in the vague hope that it works and actually understand what I'm missing!

<div class="container">
  <div class="row">
    <div class="col-2-of-3">
      <div class="video-container">
        <div class="video">Column Containing 4:3 Video</div>    
      </div>
    </div>
    <div class="col-1-of-3">
      <div class="full-height-div">
        Div in column 2
      </div>
    </div>
  </div>
</div>

css

.container {
  border: 1px dotted red;
}

.row {
  background: #aeaeae;
  width: 100%;
  height: 100%;
}
.row::after {
  content: "";
  display: table;
  clear: both;
}

[class^="col-"] {
  height: 100%;
  float: left;
}
[class^="col-"]:not(:last-child) {
  margin-right: 10px;
}

.col-1-of-3 {
  width: calc((100% - 2 * 10px}) / 3);
}

.col-2-of-3 {
  width: calc(((100% - 2 * 10px) / 3) * 2 + 10px);
}

.video-container {
  height: 0;
  overflow: hidden;
  padding-top: 75%;
  position: relative;
  width: 100%;
}

.video {
  background: red;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  text-align: center;
  color: #fff;
}

.full-height-div {
  max-width: 100%;
  height: 100%;
  border: 1px dotted #fff;
}

codepen: https://codepen.io/anon/pen/jxzMag?editors=1100

haugsand

You can use flexbox instead of floats to create the layout: A Complete Guide to Flexbox

By default, the elements in a flex row layout are stretched to 100% of the row height

Example: https://codepen.io/anon/pen/gzzvyO

.container{
  border: 1px dotted red;
}

.row{
  background: #aeaeae;
  display: flex;
}

.col-2-of-3{
  width: 67%;
  flex-grow: 0;
}

.col-1-of-3{
   flex-grow: 1;
   margin-left: 10px;
}

.video-container {
  height: 0;
  overflow: hidden;
  padding-top: 75%;
  position: relative;
  width: 100%; 
}

.video{
  background: red;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  text-align: center;
  color: #fff;
}

.full-height-div{
  height: 100%;
  border: 1px dotted #fff;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Div not maintaining a 1/1 aspect ratio when height is calculated dynamically

Maintain div aspect ratio according to height

Maintain aspect ratio of a div with dynamic height

HTML 2 column layout always full height

how to use min-height, aspect-ratio, ... with container queries?

Images aspect ratio distorted when making 100% height/width of container

DIV match height of other div with different aspect ratio responsively with JQuery

DIV container covering full height

Div full height of container / body

css to keep aspect ratio of 1:1 (square) based on parent height

contain image in 60%-height-div, while keeping aspect ratio

Maintain aspect ratio of div but fill screen width and height in CSS?

Maintain aspect ratio of div in %, knowing the height and width in px

divs positioning in parent div keeping aspect ratio by height

How to keep aspect ratio from image with animation in a div with container?

How to set Matplotlib colorbar height for image with aspect ratio < 1

Aspect ratio full screen image

Container padding image aspect ratio

CSS Aspect Ratio in flexbox container

How to make div container the full height of the screen?

Xamarin Forms Image with 100% of parent container width and auto Height to maintain aspect ratio

1:1 Aspect Ratio in CameraX

Emulating 1:1 aspect ratio

Android, XML: Show only portion of image in layout container without altering aspect ratio

How to fix div aspect ratio?

Maintain the aspect ratio of a div with CSS

Filter Rectangles with 2:1 Aspect Ratio from an array of rectangles

kivy layout: want to set the ratio of height of components to be 5:1

image height to full div height when container cant be changed