Creating a layout with multiple child elements using flexbox

I'm wondering if it's possible to achieve something like this:

using flex-boxes with only three divs inside the wrapper. I know it would be simpler to create two columns, with one wrapping the larger div and another wrapping the other two blocks, but I want to attempt it the way I described earlier.

Check out the Fiddle here

#row {
  margin: 0 auto;
  width: 610px;
}
#wrapper {
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: row;
  -ms-flex-direction: row;
  flex-direction: row;
  -webkit-flex-wrap: wrap;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
  -webkit-justify-content: center;
  -ms-flex-pack: center;
  justify-content: center;
  -webkit-align-content: flex-start;
  -ms-flex-line-pack: start;
  align-content: flex-start;
  -webkit-align-items: flex-start;
  -ms-flex-align: start;
  align-items: flex-start;
}
#x-1,
#x-2,
#x-3 {
  margin: 5px;
  background-color: red;
}
#x-1 {
  height: 250px;
  -webkit-order: 0;
  -ms-flex-order: 0;
  order: 0;
  -webkit-flex: 1 1 300px;
  -ms-flex: 1 1 300px;
  flex: 1 1 300px;
  -webkit-align-self: stretch;
  -ms-flex-item-align: stretch;
  align-self: stretch;
}
#x-2 {
  -webkit-order: 0;
  -ms-flex-order: 0;
  order: 0;
  -webkit-flex: 1 1 200px;
  -ms-flex: 1 1 200px;
  flex: 1 1 200px;
  -webkit-align-self: auto;
  -ms-flex-item-align: auto;
  align-self: auto;
}
#x-3 {
  -webkit-order: 0;
  -ms-flex-order: 0;
  order: 0;
  -webkit-flex: 1 1 200px;
  -ms-flex: 1 1 200px;
  flex: 1 1 200px;
  -webkit-align-self: auto;
  -ms-flex-item-align: auto;
  align-self: auto;
}
#x-2,
#x-3 {
  height: 50px;
}
<div id="row">
  <div id="wrapper">
<div id="x-1"></div>
<div id="x-2"></div>
<div id="x-3"></div>
  </div>
</div>

Answer №1

Compatibility: IE 11 and all modern browsers. Safari will need the -webkit- prefix for compatibility.

  • To create columns with wrapping children, set a height on the parent element and use flex-flow: column wrap.

  • Make the first child of the flex container fill the same height as its parent by using flex: 1 0 <parent height>. This will push the other children into a new column.

  • For the remaining siblings, apply flex: 1 to evenly distribute the height among them.

Example

* {
  padding: 0;
  margin: 0;
}
#wrapper {
  display: flex;
  flex-flow: column wrap;
  height: 200px;
  width: 300px;
  padding: 5px;
  margin: 0 auto;
}
#wrapper > div {
  background-color: red;
}
#x-1 {
  flex: 1 0 100%;
  margin-right: 5px;
}
#x-2 {
  flex: 1;
  margin-bottom: 5px;
}
#x-3 {
  flex: 1;
}
<div id="wrapper">
  <div id="x-1"></div>
  <div id="x-2"></div>
  <div id="x-3"></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

Retrieving Blocked Images with Selenium: A Step-by-Step Guide

HTML: <html> <head> <body onload="document.getElementById('a').style.display='block';"> <div id="a" align="center" onclick="document.location.reload();" style="display: block; cursor: pointer;"> <img width="9 ...

Selenium is displaying outdated PageSource information and is failing to refresh after running Javascript

I am working on a console program in C# where Selenium is used to control a Chrome Browser Instance, and my goal is to extract all the links from a page. However, I have encountered an issue where the PageSource retrieved by Selenium differs from the actu ...

Adding HTML to a webpage through the use of JavaScript's .innerHTML functionality

Currently in the process of creating a website template, I have made the decision to experiment with using an external JS file for inserting HTML at the top of the page to streamline navigation (eliminating the need for manual copying and pasting). My att ...

Convert a String to JSON using either JavaScript or jQuery

Currently, I am developing a JavaScript animation script and I am aiming to allow individuals to define behavior declaratively within the HTML. This is the format I envision for my HTML: <div data-animation="top: 600, left: 600, opacity: 1, start: 0.2 ...

I am looking for assistance constructing a task management application using vue.js

I am facing an issue with developing a to-do list using Vue.js. The goal is to add tasks to the list by entering them and clicking a button. Once added, the new task should show up under "All Tasks" and "Not finished". Buttons for marking tasks as " ...

Using the power of AJAX, retrieve data from a PHP script and showcase the response within

Within my HTML file, I have implemented a feature that allows users to input a value. To validate this input, I created a PHP script that checks if the entered value exists in the database. The script returns the following JSON response: {"active":true} ...

"Interactive Web Design: Create Drag-and-Drop Functionality with

Greetings! I am endeavoring to create an application featuring a straightforward HTML/CSS draggable tree layout. <div class="tree"> <div class="leaf" draggable=true> <div class="leaf-handle">item 1</ ...

Remove HTML element and launch in a separate browser tab while preserving styles

I am currently working on developing a single-page application with Polymer3 (Javascript ES6 with imports). One of the key functionalities of my application involves moving widgets to new browser windows, allowing users to spread them across multiple scree ...

container dimensions for images

Is there a way to make an image adjust its size according to the container? For example, if the container is 100x100 pixels and the image within it is 90x80 pixels, can we make sure that the smaller property of the image (height in this case) adjusts to f ...

Transferring selected text to a Cordova application from a different application

Can I extract highlighted text from a different application, such as a browser, and send it to my Intel XDK Cordova app in JSON format for utilization? (Potentially utilizing a context menu) ...

Enhance your webpage with custom styling using the html() method in jQuery

Adding style to my website using the .html() method is something I'm looking to do. I've attempted this: Using jQuery: if ($('#checkbox:checked') > 0) { $("body").html(" <style> .selected{ ...

Tips on assigning html actions/variables to a flask submit button

I am facing an issue with my Flask app where the form submission process takes a while for the backend to process. In order to prevent users from refreshing or resubmitting, I want to display a loading gif during this time. The current HTML code for my fl ...

Error encountered with Paypal code. Being redirected to error code 400

Hello everyone, I am currently working on creating a simple webpage and practicing how to integrate PayPal into our website. However, I seem to be encountering an issue where it is redirecting me to a 400 error page. Below is the code snippet that I have ...

Background image not looping in SQL database filepath

I have an image uploaded to a specific folder, and the file path is stored in a table along with other information such as title and description. I want to display this information within a repeated div element on the webpage. While the other variables loo ...

Tracking progress with a dynamic bar from the beginning to the end

Struggling to develop a progress bar that corresponds to project start dates and end dates. With a roster of 100 projects, spanning from mid-2017 to future launches, the aim is to depict progress between 2018, 2019, and 2020. If a project commenced in 2017 ...

The alignment of the HTML and CSS speech bubble is experiencing issues

I need help with CSS as I am new to it and trying to create a speech bubble. However, when the text inside the bubble is long, it overlaps the timestamp. I am currently using `display: inline-block;` in my CSS. Below are snippets of my HTML and CSS code: ...

"Placing a three.js scene within a table: A step-by-step

Is there a way to insert a three.js scene into an HTML table? Specifically, to display a cube in the first column. I attempted the following code, but it was unsuccessful: <body bgcolor="#E6E6FA"> <table style="position:relative; width:100%; bord ...

Left-align the tab elements

I am looking to customize this example for Vertical tabs. Sandbox: https://codesandbox.io/s/v0p58 My goal is to have the tabs aligned on the left side. I attempted to include: alignItems: 'left' tabs: { borderRight: `1px solid ${theme.palet ...

What is causing React Js to fail loading css when switching from anchor tag to link tag?

I am learning React and experimenting with creating a basic static website using HTML templates in version ^18.2.0 of React JS. Everything seems to be functioning correctly, however, I have encountered an issue with page refresh. Specifically, when I repla ...

Dropdown Box Linking and Input Field Integration in HTML

I have a scenario where students need to pay monthly fees for their classes. My objective is as follows: 1. Dropdown #1: Student Names 2. Dropdown #2: Month Names 3. Textbox: Fees amount for the selected month The code I am using: $(document).ready(fu ...