Creating a dynamic design with two columns using flexbox

I'm working with a small layout that consists of sections

.custom-collection {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
}
.custom-collection section {
  width: 50%;
}
<div class="custom-collection">
  <section>
    <h2>bar</h2>
  </section>

  <section>
    <h3>baz</h3>
  </section>

  <section>
    <h1>FOO</h1>
  </section>
</div>

In this design, everything is arranged in one column. The desired outcome should look like:

___________
| h2 |    |
|____| h1 |
|_h3_|____|

I understand that the layout would wrap if I set max-width, but determining the size of the div in advance is challenging. My goal is to achieve wrapping in a way that ensures both columns have equal height.

How can I accomplish this?

Answer №1

Setting the h1 section to have a height of 100% will cause it to move to a new column.

* {
    margin: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

.collection {
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    height: 100%;
}

.collection section {
    width: 50%;
    flex: 1;
    border: 1px dashed black;
}

.collection section:last-child {
    flex-basis: 100%;
}

@media ( max-width: 700px ) {
    .collection section { width: 100%; } 
    .collection section:last-child { flex-basis: auto; } 
}
<div class="collection">
    <section><h2>bar</h2></section>
    <section><h3>baz</h3></section>
    <section><h1>FOO</h1></section>
</div>

Check out this jsFiddle link for more details

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

Disabling the scrollTop() effect following a click event with onClick()

Utilizing the scrollTop() event to toggle the visibility of a div at a specific position and also using the onClick() event to permanently hide the div. While the events are functioning properly, an issue arises when scrolling the page causing the div to r ...

Issue with the alignment of form input fields and buttons in Mozilla Firefox

Fixing Form Field Alignment Issue in Firefox After encountering and solving a form field alignment issue myself, I realized that the problem persisted in Firefox while displaying correctly in Chrome. Here's how I resolved it, although I am open to mo ...

Issue caused by overflowing content and resizing the display

I am facing a challenge with my website. Essentially, my webpage has the <html> set to overflow:hidden, with two horizontal navbars, a fixed vertical sidebar on the left, and a central div with the height: 90% property. Edit: The container div now ...

Enhancing the Alignment of a Bootstrap Navbar with CSS

Having trouble centering the listed items (excluding the image and title) in the middle of the navbar. Tried various solutions with no luck! Any suggestions on how to tackle this issue? <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a ...

Creating a nested JSON structure by fetching data from a remote source

i'm looking to populate the json file located at through a get request. This json contains music from various churches in different cities, with data organized into multiple levels. I want to parse this data using jquery and utilize hidden div elemen ...

Choosing a preset value from the dropdown menu does not successfully capture the value, resulting in the data not being transmitted to the database

My issue with page.html <ion-item> <ion-label color="medium">Leave</ion-label> <ion-select [(ngModel)]="leavetype" name="leavetype"> <ion-select-option *ngFor="let val of result" value=""> {{val. leavetype}} </ion- ...

The expected values from the Express POST request were not successfully retrieved

I'm facing an issue with my Express registration page where I am unable to retrieve the input values from the HTML form as they show up as undefined. app.js: var express = require('express'); var path = require('path'); var app = ...

Unable to click on links due to issues with the CSS and HTML

On my page at , there are links on the right side that I am unable to click. Does anyone know why this might be happening? Content on the Left Side: <nav class="woocommerce-breadcrumb" itemprop="breadcrumb"><a class="home" href="http://artendije ...

Achieving a sleek line effect with a gradient border

Is there a way to make the gradient border transition between two colors look like a straight line? Additionally, is it possible to have the line start in the bottom left corner instead of the middle of the right side of the button? The current CSS code I ...

How to locate an element in Webdriver/Selenium when it lacks a class name, id, or css selector?

Within the search results displayed in groups of 7, you can find the address and phone number for each entry on the right side as follows: I need to extract both the address and phone number for each result. The challenge lies in how these elements are st ...

Eliminate parameters from the image source URL

I'm struggling to eliminate the parameters that are hindering the animation of my gif. Here's the code for the gif: <img src="/asset/News/6001/gif-anim.gif?thumbnail_width=2000&amp;thumbnail_height=500&amp;resize_type=CropToFit" heigh ...

Creating responsive modal windows in Vue and Laravel to dynamically adjust to the screen size

I am currently working with a modal window code snippet. <transition name="modal" @close="showModal = false"> <div class="modal-mask" style=" width: 90% !important;"> <div class="modal-wrapper"> < ...

Tips for maintaining accessibility to data while concealing input information

Is it possible to access data submitted in a form even if the inputs were hidden by setting their display to none? If not, what approach should be taken to ensure that data can still be sent via form and accessed when the inputs are hidden? ...

Stop the creation of new div elements once the minimum height has been reached or when text is past

Here is the HTML code I am working with: <div id='parent' align='right' dir='rtl' style=padding:0px;margin:0px;font-weight:bold;width:300px;height:auto;min-height:300px; "'<div align='right' dir='rt ...

The placement of my image shifts when I switch to the mobile view

Having a small issue with my image alignment. When I switch from portrait to landscape view, the image is no longer centered. The margin remains the same as in portrait view and I'm unsure how to adjust it. I've attempted changing the margins of ...

Aligning buttons vertically using Bootstrap 4 and styling them as anchors

I am currently trying to create a layout using Bootstrap 4 with three buttons, one large button on the left and two smaller buttons stacked on top of each other to the right. I am using btn-groups to achieve this layout. My goal is to have the large button ...

The Iframe on the webpage is automatically refreshing once a submission is made, which is not a feature present in the original version of

Within my newsletter.html file, I have set up a newsletter where users can submit their email addresses, which are then stored in my JSON file. In homepage.html, I embedded an iframe from the newsletter.html file. Everything seems to be working fine, exce ...

Enhance Bootstrap: adjust button width based on fluid text width

Incorporating Bootstrap 5 framework, I have designed a card that showcases brand information along with a navigation button on the right side. https://i.sstatic.net/25QVr.png When the description is brief, the button aligns perfectly in a single line. Ho ...

creating div elements dynamically using JavaScript

It is required that the user be able to dynamically add 5 divs by clicking on the plus icon. An alert should appear after attempting to add more than 5 divs, prohibiting any odd numbers from being added. function addvv() { var numItems = $('div.b ...

Navigation bar not adjusting to the size of the mobile device's screen

My website can be found at . I'm trying to make my navbar mobile-friendly and usable on all devices. However, when I tested it on my iPhone, the navbar appears extremely tiny. Please inspect the code using dev tools to see what I mean. Below is the co ...