Designing a Layout Using Flexbox

I'm currently attempting to design the following layout using Flexbox, but I've hit a roadblock.

The green section should occupy 20% of the page horizontally, while the two areas on the right should take up the remaining 80%. To ensure proper spacing for the content within each container, I believe it's ideal to treat them as three distinct containers in flexbox.

Can someone provide guidance on how to achieve this layout using Flexbox? I only require the CSS for each container.

Answer №1

By utilizing CSS Flexbox, you have the ability to split your layout into two parts (.left & .right) with widths of 20% and 80% respectively. Here's how:

.child.left {
  flex: 20;
  background: green;
}

.child.right {
  flex: 80;
  display: flex;
  flex-direction: column;
}

Within the .right child element, you can further divide the layout into two sections using flex-direction: column to create a top-bottom arrangement, each occupying 20% and 80% of the parent width, like this:

.child.right .top {
  flex: 20;
  background: red;
}

.child.right .bottom {
  flex: 80;
  background: blue;
}

Take a look at the live example snippet below:

body {
  margin: 0;
}

.parent {
  display: flex;
  width: 100vw;
  height: 100vh;
}

.child.left {
  flex: 20;
  background: green;
}

.child.right {
  flex: 80;
  display: flex;
  flex-direction: column;
}

.child.right .top {
  flex: 20;
  background: red;
}

.child.right .bottom {
  flex: 80;
  background: blue;
}
<div class="parent">
  <div class="child left"></div>
  <div class="child right">
    <div class="top"></div>
    <div class="bottom"></div>
  </div>
</div>

I hope this explanation proves helpful!

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

Inserting images into an HTML table using JavaScript in real-time

I am attempting to dynamically add an image into a table, but I am encountering difficulties. Whenever I try to insert an image into a cell, I receive the following error message: Cannot access the inner content because it is not literal. if ...

What is the best way to include more than two conditions in my code? For example, using if, if, else

<!DOCTYPE html> <html> <head> <title>efgh</title> </head> <body> <p id="result"></p> <button onclick="verifyInput()">check input</button> <script> function ver ...

Challenge with organizing space within a nested layout of flexboxes and CSS grids

Is it possible for my aside element and div.content to evenly split the available space in the container? Additionally, should the grid within div.content take up all the vertical space? The issue I'm encountering is that grid items aren't able ...

Issue with OpenLayers Icon not appearing on screen

I just finished creating a SpringBoot app using Spring Initializer, JPA, embedded Tomcat, Thymeleaf template engine, and packaging it as an executable JAR file. Within this app, I have integrated OpenLayers 4 library to display a map with an Icon. Howeve ...

Monochromatic CSS background transformation upon hovering

Looking for a solution with my CSS sprite setup: Here is the HTML: <a id="estates" href="http://www.domain.com/estate"></a> The corresponding CSS: #estates {background-position: -200px 0px;width: 96px;height: 90px;} #estates {background: u ...

The background widths do not stretch to 100%, but rather stop right before reaching the

Experience it live: Adjust your screen width slightly to activate the mobile layout, but ensure that there is still enough room for a horizontal scroll bar. Astonishingly, all my background images stop short of this point. Innovative Fix To prevent the ...

Creating dual modes (night/day) for your AngularJS application

Currently, I am in the process of developing a project with Angularjs and facing an obstacle with animations. My goal is to implement a feature in my application that allows it to display in two different modes - night mode and day mode. I have come ac ...

What is the method for inserting innerHTML into a static file being transmitted by node JS?

I am in the process of creating a music player website. First, I send the static file "Music_file.html" using node JS. Then, I utilize a database in nodeJS to retrieve a list of song-related information and attach it to the class 'song-item'. The ...

Utilize jQuery to dynamically load and assign unique ids to elements within an array

I am seeking assistance with dynamically assigning unique IDs to elements in an array using JavaScript and jQuery. I am new to these languages and need some guidance. function assignIds() { var elementIds = ['name', 'lname', ' ...

When using iOS, the video compressing process stops automatically if the screen is no longer active while the file input

I am working on a web application that includes a file upload feature for large videos, typically 30 minutes or longer in duration. When a user on an iOS device selects a video to upload, the operating system will automatically compress it before triggerin ...

What is the best way to convert my create-react-app project into a standalone HTML file that includes embedded JavaScript?

For a test assignment for a new job, I completed a simple create-react-app project. However, there is a requirement that the project must be submitted as a single HTML file with embedded JS and CSS. How can I convert my create-react-app project into a sin ...

Issue with Django link not functioning properly within a for loop

My attempt to enclose a piece of table data in an HTML table with a link seems to be resulting in some unexpected behavior when viewed in Chrome's Element Viewer. <a href="/tasks/1/"></a> <a href="/tasks/2/"></a> <a href="/ ...

The footer lies at the bottom of the page, demarcated by

I'm struggling to position the footer at the bottom of the page with a horizontal line just above it. Despite trying various resources, I can't seem to get the footer to stay at the bottom. I'm currently using a blog template as the basis fo ...

Issue with React Hot Toast not displaying properly due to being positioned behind the <dialog>

The Challenge of Toast Notifications Visibility with <dialog> Element tl;dr When utilizing the native dialog.showModal() function, the <dialog> element appears to consistently remain on top, which causes toast notifications to be obscured by ...

How can I write a click event for an image within a PNG using jQuery?

Is it possible to add a click event to an image with a hole inside, allowing the image behind it to show through? Check out this JSFIDDLE for reference //javascript code $('#ant').click(function() { alert("hi"); }); ...

What is the method for retrieving the value from a text input using JavaScript?

let userInput = document.getElementById('myFieldId'); console.log(userInput.value); <!DOCTYPE html> <html> <head> </head> <body> <input type="text" id="myFieldId"/> <script src="main.js">< ...

What is causing the delay in updating the images every 2 seconds?

let counter = 0; function change() { if (counter < results.length) document.getElementById("container").style.backgroundImage = `url(static/letters/${results[counter++]}.jpg)`; } window.onload = function() { setInterval(change, 2000); }; ...

Troubleshooting issues with CSS fixed and absolute positioning in Chrome

Something strange is happening on my website with the static header bar. It works perfectly everywhere except for one page and only in Chrome. The div with class "top-bar" is set to position: fixed. <header> <div class="top-bar"> & ...

The alignment of the text is incorrect and needs to be fixed

In my code, I have an if statement that determines how the page should be rendered. <script language="JavaScript"> if (NS4) { document.write('<LAYER NAME="floatlayer" LEFT="22" TOP="60">'); } if ((IE4) || (NS6)) { document.w ...

Name values not appearing in dropdown list

Looking for some assistance with displaying a list of names in a dropdown menu using Angular. The dropdown is present, but the names from my array are not appearing. I think it might be a simple fix that I'm overlooking. I'm new to Angular, so an ...