What is the best way to create this layout using flexbox in CSS?

Can anyone provide guidance on how to create the design shown below using flexbox?

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

Answer №1

Start by creating a container and splitting it into 2 halves using the flex property.

Next, divide the first half further into two sections with an 8:2 ratio by applying the flex property to the child flex-elements.

.container {
  display: flex;
  gap: 1rem;
}

.box {
  height: 200px;
  flex: 1;
  background-color: blue;
}

.box1 {
  background-color: white;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.internal-box1 {
  flex: 8;
  background-color: blue;
}

.internal-box2 {
  background-color: blue;
  flex: 2;
}
<div class="container">
  <div class="box box1">
    <div class="internal-box1"></div>
    <div class="internal-box2"></div>
  </div>
  <div class="box"></div>
</div>

Answer №2

Consider trying out this code snippet:

<div style="
    height: 250px;
    width: 100%;
    display: flex;
"><div style="
    display: flex;
    flex-direction: column;
    flex: 1;
    margin-right: 20px;
"><div style="
    flex: 1;
    background-color: paleturquoise;
    margin-bottom: 20px;
"></div><div style="
    height: 40px;
    background: blue;
"></div></div><div style="
    flex: 1;
    background: teal;
"></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

Incorporating Bootstrap styling into a ReactJS project

I've been experimenting with integrating Bootstrap into my React project. While I have successfully implemented Bootstrap buttons and grids, I'm facing an issue where the CSS styles for Bootstrap are not being applied. Is there a way to manually ...

Using JQuery to visually enhance the menu selection by displaying an image and altering the background color upon hovering

Hello fellow JQuery/Javascript beginners! I recently put together a menu and wanted to add some interactive elements. Specifically, I want the background color to change when a user hovers over an item (simple enough with CSS), but I also want to include a ...

Tips for adjusting a div to perfectly fit your screen height

When I try to display images or videos in modal divs, they end up being taller than my screen size: Here is my code snippet: <div class="modal fade" id="showMedia" tabindex="-1" role="dialog" aria-hidden="true"> < ...

Center text and image within a button

Can anyone help me create a LIKE button that is aligned in the middle center with text and image? I'm struggling with responsiveness and it's driving me crazy. I feel like I might be overcomplicating things. Can someone simplify it for me and ma ...

Looking for a simple method to generate a text-only dropdown link in Bootstrap 4 without using a button?

Is there a simple method to create a text-only dropdown link in Bootstrap 4 without using a button? Or do I have to adjust the padding and buttons using CSS to make the "Delivery" dropdown blend in with the rest of the text? I've searched online and ...

Display or Conceal Sub-Header according to Scrolling Position

Question: My goal is to create a specific animation on my website. When loading the page on mobile, I want to display the div with ID "sub-header", but once the user scrolls more than 50px down, I want to hide it. Additionally, if the user scrolls up by 60 ...

Issue with displaying elements at intended layering order when parent element has fixed positioning

My web app features both upper and lower elements (div) with a position: fixed. Each element has child popups also with position: fixed. Even though I want to position the popup above its parent element, using z-index doesn't work due to inheritance ...

Is it possible to combine and compress HTML/CSS/JS files using npm?

When organizing my CSS code and directory folders, I like to use multiple stylesheets to keep things tidy. However, it appears that @import is not recommended in CSS. Instead, combining your code (as @import does) and minifying it by removing comments, spa ...

Learn how to dynamically disable a button using jQuery within the Materialize CSS framework

While attempting to disable a button in Materialize CSS using jQuery, I encountered an issue. Despite following the documentation found here, it seems that simply adding the 'disabled' class does not automatically disable the button as expected. ...

Stop users from being able to copy text on their smartphones' internet browsers

I am currently working on creating a competitive typing speed challenge using JavaScript. Participants are required to type all the words they see from a div into a textarea. In order to prevent cheating, such as copying the words directly from the div, o ...

There seems to be an issue with Affix functionality in Bootstrap 4 (alpha version)

As detailed in the Bootstrap 3 documentation, I have included the following attributes in a navbar: <nav class="navbar no-margin-bottom" data-spy="affix" data-offset-top="90" > ... </nav> Unfortunately, when scrolling down the page with Boots ...

The button is out of alignment with the rest of the components in Bootstrap

Is there a way to align the button with other components on the same line, positioned above them? https://i.sstatic.net/m5Abz.png <div className="row mb-12"> <div className="col-md-3"> <label htmlFor="noOfSubjects">No Of Subject ...

Leveraging the power of Vue.js for a solo project

I've been diving into learning Vue.js for my job, and while I've grasped the syntax, I have a specific query regarding setting up a full project. Up to this point, I've used npm to start a project, either through the command line or by util ...

What is the best way to remove the background from a button that uses -moz

After adding the select component to my page, I noticed a problem with the select button in Firefox. In Chrome, the arrow down button looks normal, like this, but in Firefox it appears differently, as shown in this image. How can I remove the background ...

Float one navbar item to the right in Bootstrap4 and maintain center alignment for the links

I'm attempting to align the "login with discord" text and image to the right while keeping the other 2 navbar links centered. However, every time I try to float it right, the centered content/nav items get shifted to the left by the width of the "logi ...

Tips for implementing the .nex() property from jQuery in CSS styling

When I add the class "playing", then I will apply custom CSS to the next li tag. Please review my code and see if you understand. Please take a look at my code. <ul> <li class="playing">li (sibling)</li> <li id="head">li ...

HTML and CSS: Focus on border for <td> cells only

I'm looking to apply a border to only one cell (B2) without nesting tables. Here's the code: <table border="0"> <tr> <td>A1</td> <td>B1</td> <td>C1</td> </tr> ...

White space in Bootstrap 4 grid caused by a full-width row

I have set up a bootstrap grid layout that includes ads, and I wanted to integrate a section for banners within it. After some experimentation, I managed to achieve this by inserting a container between the ads and the banners, each housed in their own row ...

The collapsible navigation bar in Bootstrap

I'm having issues with my Bootstrap collapsible menu. Can someone help me identify the problem? <nav class="navbar navbar-default navbar-fixed-top"> <div class="container-fluid"> <div class="navbar-header"> <a class= ...

Angular: Creating an input field with preset value that is immutable

I am a beginner with angular and I have been working on this code snippet: <mat-form-field appearance="outline" class="col-30" id="mat-identifier"> <mat-label> {{'columns.dashboard.identifier' | ...