Ensure that each of the two divs maintains a 16:9 aspect ratio, and utilize one div to fill any remaining empty space through the

This layout is what I am aiming for:

While I can achieve a fixed aspect ratio with a 16:9 image by setting the img width to 100%, I run into an issue where the height scaling of flexbox becomes non-responsive. The height remains constant, and only the first row adjusts its height when resizing the window. The second row overflows and does not change in height whatsoever. In an attempt to address this, I experimented with adding a third div in the middle to occupy any remaining space when the viewport height decreases. This adjustment would make both image1 and image2 smaller while expanding the middle div.

My inquiry is as follows: Is it feasible to accomplish this using flexbox, or should I resort to utilizing css grid or javascript?

HTML:

<div id="container">
      <div id="row1">
            <div id="panel1"></div>
            <div id="panel2"></div>
      </div>
      <div id="row2">
            <div id="panel3">
              <img/>
            </div>
            <div id="panel4"></div>
            <div id="panel5">
               <img/>
       </div>
</div>

CSS:

#container {
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-wrap: wrap;
    flex-direction: column;
}

#row1 {
    display: flex;
    flex-wrap: wrap;
    flex: 2;
    gap: 7px;
    width: 100%;
    padding: 7px;
}
#row2 {
    display: flex;
    flex-flow: row nowrap;
    flex: 1;
    gap: 7px;
    width: 100%;
    padding: 0 7px 7px 7px;
}

#panel1 {
    background: white;
    flex: 1;
}

#panel2 {
    background: white;
    width: 100px;
}

#panel3 {
    background: white;
    flex: 1;
}

#panel4 {
    background: white;
    flex: 1;
}

#panel5 {
    background: white;
    flex: 1;
}

#image1 {
width: 100%;
}

Answer №1

Update the styling of panels 3 and 5 by removing flex: 1 and setting an aspect-ratio of 16/9.

#panel3 {
  aspect-ratio: 16 / 9;
}

#panel4 {
  flex: 1;
}

#panel5 {
  aspect-ratio: 16 / 9;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

#container {
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
}

#row1 {
  display: flex;
  flex-wrap: wrap;
  flex: 2;
  gap: 7px;
  width: 100%;
  padding: 7px;
}

#row2 {
  display: flex;
  flex-flow: row nowrap;
  flex: 1;
  gap: 7px;
  width: 100%;
  padding: 0 7px 7px 7px;
}

#panel1 {
  background: red;
  flex: 1;
}

#panel2 {
  background: orange;
  width: 100px;
}

#panel3 {
  background: yellow;
  aspect-ratio: 16 / 9;
}

#panel4 {
  background: green;
  flex: 1;
}

#panel5 {
  background: blue;
  aspect-ratio: 16 / 9;
}

#image1 {
  width: 100%;
}
<div id="container">
  <div id="row1">
    <div id="panel1"></div>
    <div id="panel2"></div>
  </div>
  <div id="row2">
    <div id="panel3">
      <img/>
    </div>
    <div id="panel4"></div>
    <div id="panel5">
      <img/>
    </div>
  </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting issue with file upload feature in Angular for Internet Explorer 9

I have implemented a file upload method using the following code: <input type="file" name="upload-file" ng-model= "excelFile" accept=".xlsx" onchange="angular.element(this).scope().fileChanged(this);" ...

Using class binding for both ternary and non-ternary attributes

Suppose we have a tag that utilizes a ternary operator to apply alignment: <td :class="alignment ? ('u-' + alignment) : null" > This functions as intended since the pre-defined alignment classes are in place, now if we want to ...

I'm having trouble obtaining accurate results for $....<...$ within the <li> tags using MathJax

I have gained extensive experience working with LaTeX formatting, but not every document follows the standard practice of having a space before and after the symbols < and >. When I attempt to use MathJax to display these documents, they fail to render pro ...

When decoding a JWT, it may return the value of "[object Object]"

Having some trouble decoding a JSON web token that's being sent to my REST API server. I can't seem to access the _id property within the web token. Below is the code I'm currently using: jwt.verify(token, process.env.TOKEN_SECRET, { comp ...

Unable to get the onchange event to trigger for a span element

Is there a way to trigger the onchange event on a span element that doesn't seem to be working? Here is the code I am using: Attempt 1 document.getElementById(seconds).addEventListener('change', (event: MutationEvent & { path: any }) =& ...

Troubleshooting the Angular Fullstack + CORS issue: "XMLHttpRequest cannot load

I've been wracking my brain trying to figure this out. Utilizing the yeoman generator angular-fullstack, I created a simple Angular app on a NodeJS server with Express. The app makes remote service calls, so there are no API server side calls within ...

Error: The function 'myAppController' is not defined and is therefore not a valid argument

I am trying to incorporate my service into my controller and print a message to the console (in the Auth Service), but I keep encountering this error: Argument 'myAppController' is not a function, got undefined. Can you help me figure out what I& ...

Incorporating stick-to-top scroll functionality using AngularJS and ng

I am trying to implement a 'sticky' scroll on dynamic content. My current working example can be found here. It seems to be working, but I encounter a small 'flicker' when new items are appended. This issue seems to be related to the se ...

A guide on how to retrieve POST form fields in Express

My form design is quite simple: <form id="loginformA" action="userlogin" method="post"> <div> <label for="email">Email: </label> <input type="text" id="email" name="email"></input> </div> & ...

Understanding the inner workings of a Mongoose model without the need for

server.js process.env.NODE_ENV=process.env.NODE_ENV || 'development'; var mongoose=require('./config/mongoose'); express=require('./config/express'); var db=mongoose(); var app=express(); app.listen(3000,function(){ ...

Tips for setting up my bot to pull random messages from a channel and send one when an autoresponse is activated

As per the headline, I attempted to utilize fetchMessages in order to monitor the messages being sent in a specific channel. However, when I experimented with this method, it simply generated never-ending blocks of data in the console. Upon inspection, I ...

Error: The function of Bootstrap toggle is not defined

Currently, I am working on a Django application for warehouses and stockists. My goal is to create a list of stockists per warehouse in a button list format. When this button is clicked, a modal window should appear displaying the name, position, and permi ...

Sending a JavaScript variable to PHP in order to specify the timezone

I'm working on setting the timezone for every user in the navbar.php file that's included on all pages of my website. After finding a helpful js script, I am able to echo the variable 'Europe/Brussels' to identify my timezone correctly. ...

The definition of require is missing in the MEAN stack node

Currently experimenting with building an application on the MEAN stack and encountered a hurdle involving the use of Node's require function. Here is my current project structure: -- app -- images -- scripts -- app.js // configuration fi ...

Is there a way for me to retrieve information from a different website using a URL, similar to how Digg's submit button works

Currently, I am in the process of developing a website with the cakePHP framework. As a beginner in PHP and web programming, my goal is to implement a feature similar to Digg's submit button. This functionality would involve inputting a URL, which the ...

I am unsuccessful in transferring the "side-panel content" to the side panel located on the main menu page

I am facing an issue where I want to pass My left and right Panel to the main menu page (dashboard), but it is not working as expected. The problem arises because the first page that needs to be declared is the login page (/ root) in my case. If I pass it ...

Receive information on browser activity

Is there a way to trigger an event when the following actions occur: Pressing the reload icon in the browser Pressing the Back or Forward icon in the browser Selecting the Reload menu item from the browser context menu Selecting the Reload option from t ...

Converting an array of objects into an array of Objects containing both individual objects and arrays

I am dealing with an object const response = { "message": "story records found successfully", "result": [ { "created_AT": "Thu, 13 Jan 2022 17:37:04 GMT", ...

Exploring ways to utilize Next.js (React) for formatting date and time with either Moment.js or alternate

When deciding on the best method for handling date formats in my next front-end app, should I use Moment.js or JavaScript functions? The data is sourced from the backend as the date type, and I want it to be displayed in a user-friendly format while consid ...

Working with ng-model on an array with multiple dimensions

Currently, I am working on storing data in AngularJS. My table consists of various sections, rows, and columns. In each field, there is a dropdown list with the options "O", "T" or "E". My goal is to store these values in an array format: [section][row][c ...