Looking to create a row-column-row layout using CSS flexbox techniques

`

I am trying to create a unique row-column-row layout using CSS flexbox. Below is the code snippet I have:

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

.container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2%;
}

.box {
  color: white;
  background: royalblue;
  min-height: 100px;
  min-width: 100px;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px solid;
}

.b1 {
  flex: 1 0 80%;
}

.b2 {
  flex: 1 1 auto;
}

.b3 {
  flex: 1 0 100%;
}
<div class="container">
  <div class="box b1">1</div>
  <div class="box b2">2</div>
  <div class="box b3">3</div>
</div>

This design concept depicts what I am aiming for:

https://i.sstatic.net/cpFu2.png

For mobile devices, I prefer a layout similar to this:

https://i.sstatic.net/gLnKi.png

The issue lies in the fact that the column is not expanding vertically and I'm unable to utilize margins or gaps between the div elements as per the current code.

Kindly provide any suggestions. Alternatively, if you have CSS-Grid solutions, they are also welcomed.

Answer №1

A responsive design solution utilizing grid layout:

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

.container {
  display: grid;
  grid-template-columns: 4fr 1fr;
  grid-auto-rows: minmax(100px, auto);
  grid-template-areas:
    "b1 b2"
    "b3 b2";
  gap: 0.2%;
}

@media screen and (max-width: 480px) {
  .container {
    grid-template-columns: 1fr;
    grid-template-areas:
      "b1"
      "b2"
      "b3";
  }
}

.box {
  color: white;
  background: royalblue;
  min-height: 100px;
  min-width: 100px;
  border: 1px solid;
}

.b1 {
  grid-area: b1;
}

.b2 {
  grid-area: b2;
}

.b3 {
  grid-area: b3;
}
<div class="container">
  <div class="box b1">1</div>
  <div class="box b2">2</div>
  <div class="box b3">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

Ways to make <li> elements display inline with React Bootstrap Rows and Columns

I have some content that I need to format and display in a horizontal list. When I only use HTML elements in the list, it appears horizontally as expected. However, when I incorporate React Bootstrap grid layout components like Row and Column, the list dis ...

How to retrieve the width of an unspecified element using JavaScript

Seeking help with a div element that adjusts its size based on the elements it contains. How can I determine the final size of this dynamic div without checking the sizes of its internal elements? I've attempted to parse all the properties of the obj ...

What are the best scenarios for employing Server Side Includes?

The documentation for Apache regarding SSI mentions that it is a convenient method to incorporate small snippets of information, like the current time. However, if most of your webpage content is being dynamically generated when served, then it suggests ...

Tips for retrieving the user-input value from an HTML text field

Exploring the world of JS, I set out to create a basic calculator after just one week of lessons. However, I hit a roadblock when trying to extract user-input values from my HTML text fields. Here's a snippet of my html: <div class="conta ...

Implement the map function to validate every input and generate a border around inputs that are deemed invalid or empty upon button click

Currently, I'm in the process of developing a form with multiple steps. At each step, when the next button is clicked, I need to validate the active step page using the map function. My goal is to utilize the map function to validate every input and ...

How can a JavaScript function be used to check a tag's status?

I currently have two select tags on my webpage. I want to ensure that only one option can be selected at a time from these two tags. If the user tries to select options from both tags, an error message should be displayed instructing them to choose only on ...

Is it possible to eliminate the black bars from YouTube HQdefault image using only CSS?

(After searching extensively, I couldn't find the exact same question and answer) I have a dilemma with displaying YouTube's hqdefault thumbnails on my page. It seems that they are 480 by 360 pixels, resulting in black bars at the top and bottom ...

What steps can be taken to ensure an animation does not continually reset to its original state when run infinitely?

I am looking to create an animation that continues infinitely without returning to its original state after completion, similar to a sun moving animation. Below is a sample project: .animator3{ -webkit-animation-name:j3; -webkit-animation-delay:0s; -web ...

Utilize Express Handlebars to render an input-generated list for display

My goal is to showcase a collection of wishlist items on a basic webpage through user interaction. Here's how I envision it: 1. do something 2. do another thing 3. blahblah This snippet shows my index.js code: var wishlist = []; router.post('/& ...

Responsive Material-UI horizontal navigation bar

Hey there! I'm working on developing a UI using Material-UI, and I want to make it so that the menu can be collapsed into a slide-in style menu when accessed on a mobile device. Currently, I'm using tabs which allow for sliding left and right, b ...

Do CSS Stylesheets load asynchronously?

Is there a difference in how stylesheets are loaded via the link tag - asynchronously or synchronously? In my design, I have two stylesheets: mura.css and typography.css. They are loaded within the head section of the page, with typography.css being load ...

The Tumblr HTML code is not valid: There is a stray start tag for `html

Occasionally, I check my tumblog for validation in order to fix any errors. While most issues are easy to explain, there is one that has me stumped. What exactly does this mean? (please note: the outputted markup is out of my control) Error: Error: Stra ...

Removing the gaps within table cell contents

Is there a way to eliminate the border space between cells in a table? Despite using cellspacing, I still see a thin white border. Any suggestions on how to fix this? <body> <center><table style="border-collapse: collapse; width:400px; bo ...

Font-face src with local() is incompatible with Android devices

(I apologize for not discovering this earlier, but it seems that Chrome-Android also does not support the font I intended to use. The fallback-to-sys-default-font-trick used by Chrome-Android did fool me.) I had planned to incorporate unicode-range to add ...

Is there a simple and efficient method to transition the loading of a regular website to AJAX for the entire site?

Is it feasible to easily and quickly change all links on a website to load the URL that the user clicked via AJAX, rather than refreshing the webpage? My website currently has standard links, but in order to create a mobile application for iPhone, I need ...

Is there a way to access the variable value chosen from a select dropdown inside a function and then assign it to a JavaScript variable outside of the function?

Below is the HTML and JavaScript code that I am working with: function changeResult() { x = document.getElementById("dropdown-list").value; console.log((x)); } var qq; <select id="dropdown-list" onchange="changeResult()"> <option value="4 ...

Is there a way to only refresh the div specifically for the calendar with an id of "

$(document).ready(function() { $("#client-list").on("change", function() { var selectedValue = $(this).val(); location.reload(); }); }); Is there a way to refresh only the div with id='calendar' without refreshing the entire pa ...

Angular implementation of a dynamic vertical full page slider similar to the one seen on www.tumblr

I'm determined to add a full-page slider to the homepage of my Angular 1.x app After testing multiple libraries, I haven't had much luck. The instructions seem incomplete and there are some bugs present. These are the libraries I've experi ...

MailChimp consistently applies the "color: inherit !important" style to links, causing them to appear blue when viewed in Outlook

No matter how hard I try, MailChimp insists on styling any <a> tag with an href attribute to have color: inherit !important; text-decoration: inherit !important. This is causing my links to appear blue and underlined in Outlook, which is quite frustr ...

issue with border color staying the same when focusing

I've been struggling with changing the border on focus in my code. Despite trying various methods, nothing seems to be working. Can someone help me figure out what I'm doing wrong? <input type="text" spellcheck="false" data-placement="top" id ...