Flexbox does not support sub-columns

I'm having trouble integrating these two columns along with their sub-columns. I have to resort to using this structure instead:

<div class="custom_classes">
<div class="custom_classes">col1</div>
<div class="custom_classes">col2</div>
<div class="custom_classes">col 2.1</div>
<div class="custom_classes">col 2.2</div>
<div>

Answer №1

Why not try CSS grid?

One efficient way to achieve this is by utilizing CSS grid, which also ensures responsiveness.

Utilizing the CSS property grid-column

This particular property acts as a shorthand for both grid-column-start and grid-column-end

Check out more details: https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column

By using Firefox DevTools, you can simply click the grid button within the code to make a visualizer appear...

During my exploration, I discovered that creating a 4 column grid layout was the most effective approach.

If you want to explore further, here's the code :)

body {
  display: grid;
  place-content: center;
  height: 100vh;
}

.container {
  display: grid;
  gap: 0.5em;
  height: 80vh;
  width: 80vw;
}

.container .child {
  background: lightblue;
  display: grid;
  place-content: center;
}

.child1 {
  grid-column: 1/2;
  grid-row: 1/3;
}

.child2 {
  grid-column: 2/4;
}

.child3 {
  grid-column: 2/3;
}

.child4 {
  grid-column: 3/4;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <div class="container">
    <div class="child child1">col1</div>
    <div class="child child2">col2</div>
    <div class="child child3">col 2.1</div>
    <div class="child child4">col 2.2</div>
  </div>
</body>

</html>

Answer №2

Implementing Flexbox

.container{
  background: whitesmoke;
  position: relative;
  width: 100%;
  height: 300px;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  margin: 20px auto;
  display: flex;
}

.item{
  background: #d3f9d2;
  padding: 5px;
  margin: 5px;
  text-align: center;
  line-height: 200px;
  font-weight: bold;
  
}

.column1{
  width: 60%;
  height: 95%
}

.column2{
  width: 40%;
  height: 50%;
  
}

.col2_1{
  width: 18%;
  height: 39%;
  margin-right: 10px;
}
.col2_2{
  width: 18%;
  height: 39%;
  margin-left: 10px;
}

.col2_1 {
  align-self: end;
  position: absolute;
  right: 19%;
}

.col2_2 {
  align-self: end;
  position: absolute;
  right: 1px;
  
}
<div class="container">
  <div class="column1 item">Column 1</div>
  <div class="column2 item">Column 2</div>
  <div class="col2_1 item">Column 2.1</div>
  <div class="col2_2 item">Column 2.2</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

Can the ::before selector be used in HTML emails?

Hey there, I have a question that might sound silly but I'm having trouble finding an answer online. My issue is with styling the bullet point before a list item in an HTML email. All I want to do is change the bullet point to a square and give it a ...

Inject pure HTML code into a react div

I have extracted raw HTML content stored in the database and I am attempting to display it within a div element. const style = { border: '2px solid #eee', height: '270px', width: '100%', overflow: 'auto&ap ...

Is there a way to initiate a jquery function upon loading the page, while ensuring its continued user interaction?

On my webpage, there is a JavaScript function using jQuery that I want to automatically start when the page loads. At the same time, I want to ensure that users can still interact with this function. This particular function involves selecting a link tha ...

The slideUp and slideDown functions are not functioning properly

Whenever a user clicks on image-exp, I want description-exp to slide down while other description-exp slides up. I am currently using a Bootstrap template available at this link. To demonstrate the issue, I created a JSFiddle that can be accessed here. H ...

Creating a webpage that loads directly to a specific section of content

After searching online, I couldn't find the solution I was looking for. My goal is to have the visible part of the page load halfway down the actual page. This way, when users visit the site, they can immediately scroll up to see more content. I hope ...

Is the Data Being Saved: Verifying if the Value Has Been Altered?

Imagine your form containing numerous fields, where typically only 1 or 2 are modified and require saving. What approach do you take? Update the database with all values, regardless of any changes. Utilize form states to post back only the changed values ...

The table width is malfunctioning on Firefox when viewed in HTML

I have been puzzled by the fact that I am unable to adjust the width of the table th in Firefox browser to the smallest value. However, in Chrome browser, this functionality works perfectly. I simply want to divide the values of my td into three rows as sh ...

HTML: Dealing with issues in resizing and resolution with floating elements on the left and right using

Encountering some issues with the HTML code below when resizing the window: 1: The right bar suddenly drops down if the width is made too small. 2: The spacing between the content and the right bar expands as the window width increases. <style ty ...

Guide on solving the issue of a bootstrap 4 carousel loop within WordPress posts

Is it possible to create a dynamic Bootstrap 4 carousel within Wordpress custom post types? Here is the code snippet: <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel"> <ol class="carousel-indicators"> < ...

numerous inquiries regarding my CSS header navigation bars

As someone who is new to CSS, I find myself struggling to grasp the correct approach. Online examples vary and leave me confused. Specifically, I have questions about my markup but overall, am I doing things correctly? I feel like my CSS code is bloated. ...

What can be used instead of the html5 output tag?

After creating a webpage with a form that includes several "number" input fields, I utilized the html output tag to showcase the results. However, when viewed in MSIE, although the calculations were successfully done, the output tag failed to display the ...

Updating div width in Laravel blade using expressions or jQuery can be a simple task

Is there a way to dynamically change the width value of a div element based on a variable? The div contains blocks, and the size of each block is determined by the variable. For example, if $t->spotdiff = 2, I would like two equal blocks in a column wit ...

Show the center portion of an image without needing to know the size, both horizontally and vertically aligned

I have experimented with various methods like table-cell, but none of them have been successful. All I am seeking is an <img src="" /> within an <a> tag. The <a> element has specific width, height, and overflow:hidden properties set. H ...

An undefined PHP index error was encountered by Ajax, while the other one did not face the same issue

I encountered an issue with ajax where I am receiving an undefined index error on my variables when making a call. Strangely, I have other ajax calls functioning perfectly fine across my website except for this particular one which is giving me troubles. I ...

Tips for effectively applying an image as a border

Just starting out with HTML and CSS here, and I'm trying to figure out how to use an image as a border for a div element. Can someone help point out my mistake? div { width: 240px; height: 510px; background-color: lightblue; border-image ...

jQuery - Modify Turn.js to exclusively implement the page Peel effect

I am attempting to implement the peel effect from turn.js into my code, where hovering over the bottom right corner of the page causes it to peel slightly and appear as if it is bending upwards. I specifically want only the peel effect and not the entire ...

Customizing Big Cartel's Neat theme: A guide to eliminating the blur effect on featured product images upon site activation

My website is built on Big Cartel using the Neat theme. Every time the homepage loads, the Featured products images appear blurry for about 4 seconds, especially if you're not using Chrome browser. Is there a way to remove this blur effect? Thank yo ...

Ways to display HTML elements depending on the width of the window

Is there a way to create visually appealing hexagon containers for text that work well across all window widths? Currently, the design is only satisfactory at certain window sizes. I am looking to implement a solution where specific code will be displayed ...

Execute the function when the control becomes visible

Currently, I possess an input control: <input id="someID" class="form-control" type="text" name="SomeData" data-ng-model="vm.SomeData"> I have a requirement to set the initial value of vm.SomeData upon user scrolling down to this control. As a begi ...

Fetching the entire webpage

When attempting to load a specific webpage using an iframe, I encountered the following issue: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></ ...