Get rid of unnecessary spacing in flexbox items

Hey there! I have a little design puzzle that needs solving.

On mobile, everything looks great with 3 items displaying in full width. But on desktop, I'm facing a challenge:

I want section A to be right above section B, while section C should remain on the right side. However, there's some unwanted space around section A that I can't seem to get rid of.

For mobile (current setup is working fine for this code snippet): https://i.sstatic.net/scwWa.png

Expected Desktop Look: https://i.sstatic.net/Oimf2.png

Actual Desktop Output: https://i.sstatic.net/F9Z9L.png

If you could take a look at my code snippets and help me achieve the desired effect, that would be awesome!

.flex{
  display: flex
}

.flex-col{
  flex-direction: column
}

.bg-blue-50{
  --tw-bg-opacity: 1;
  background-color: rgb(239 246 255 / var(--tw-bg-opacity))
}

.bg-purple-50{
  --tw-bg-opacity: 1;
  background-color: rgb(250 245 255 / var(--tw-bg-opacity))
}

.bg-red-50{
  --tw-bg-opacity: 1;
  background-color: rgb(254 242 242 / var(--tw-bg-opacity))
}

@media (min-width: 640px){
  .sm\:w-4\/12{
    width: 33.333333%
  }

  .sm\:w-8\/12{
    width: 66.666667%
  }

  .sm\:flex-row{
    flex-direction: row
  }

  .sm\:flex-wrap{
    flex-wrap: wrap
  }
}
<div class="flex flex-col sm:flex-row sm:flex-wrap">
  <div class="bg-red-50 sm:w-8/12">Section A</div>
  <div class="bg-purple-50 sm:w-4/12">Section B
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the indu...unchanged. 
  </div>
  <div class="bg-blue-50 sm:w-8/12">Section C</div>
</div>

Answer №1

To achieve the desired layout using Flexbox, you need to modify the markup by wrapping sections A and C in their container:

<script src="https://cdn.tailwindcss.com"></script>

<div class="flex flex-col sm:flex-row sm:flex-wrap">
  <div class="sm:w-8/12">
    <div class="bg-red-50">Section A</div>
    <div class="bg-blue-50">Section C</div>
  </div>
  <div class="bg-purple-50 sm:w-4/12">Section B Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen
    book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
  </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

Placing information into a table cell using d3 library

Looking to insert text into a cell using d3? I have a function with the necessary code, which I am calling in the body of an HTML page. Here is a sample of the code that I am trying to get working: <!DOCTYPE html> <html> <head> <link ...

AngularJS scope watch isn't firing as expected

In the scope, I store a filtering string for dates. $scope.myModel = {date:""}; Utilizing a jQuery datepicker, <input date-value="myModel.date" date-picker /> This directive updates the string through AngularJS - Attribute directive input value c ...

Guiding motion of a parental container using a button

This seems like a fairly straightforward task, but I'm getting a bit frustrated with it. Is there a way to move an entire div by simply holding down the mouse button on a particular button? let container = document.getElementById('abo ...

Unable to set focus on a disabled button programmatically, issue persists

$(function () { $('#save').click(function() { $('#save').attr('disabled', 'disabled'); console.log($(document.activeElement).attr('id')); }); $('#test').focus(); co ...

I'm seeking assistance with a frontend script problem. I'm curious if there are alternative approaches to coding this script that may be more effective. Can anyone offer guidance on this?

As a frontend developer specializing in script injection, I have been utilizing Adobe Target to inject scripts. However, this method presents several challenges: 1. It is difficult to debug code errors as my HTML and CSS are wrapped inside ' ' a ...

Is it possible to dynamically adjust the width of table columns using CSS/LESS on a per-column basis?

In this scenario, the table's column width is determined by the number of columns present. For example, if there are 4 columns in the table, each column's width would be set to a maximum of 25% of the table's overall width. With 3 columns, t ...

unable to retrieve element values using class names

I have created multiple h1 elements with the same class names listed below. <h1 class="h1">One</h1> <h1 class="h1">Two</h1> <h1 class="h1">Three</h1> <h1 class="h1">Four</h1> I have also added a button that ...

Tips for sending the output of a Python function to the webpage associated with the clicked action button in Python's Bottle framework

Here is a method I have: @post('/home', method='post') def myFunction(): if(len(request.forms.get('Matrix_dimension').strip()) != 0): length = int(request.forms.get('Matrix_dimension').strip()) tableRow = ...

Creating a dynamic slideshow with automated arrow navigation is simpler than you may think

I have successfully tested the slideshow and it is functioning perfectly without any issues. I would like to have a dual slideshow setup (slideshow 1 and slideshow 2) with next and previous buttons, but I am interested in adding an automatic sliding featur ...

What impact do media queries have on scaling web pages?

Why does the page scale change with media queries? @media only screen and (min-width: 500px) { body { background-color: blue; } } @media only screen and (min-width: 800px) { body { background-color: green; } } @media only screen and (min-width: 1000px) ...

Is the fixed header see-through?

I have a query regarding my website design. Currently, the fixed header on my site is transparent and when I scroll down, the content overlaps the header. However, I want the header to remain above the content. Can anyone provide assistance with this issue ...

Limit the number of words in an HTML input box

Is it possible to set a maximum word limit for a textbox that a user can input, rather than limiting the number of characters? I did some research and discovered a way to determine the number of words a user has entered using regular expressions, but I& ...

Guide to Removing Border Radius from Card Header in Bootstrap 4

Is there a way to remove the border radius from the card-header in bootstrap 4? I tried using the code below, but the background color of the card-header is still overlapping, giving the appearance of border-radius: .card-header { height: 50px; ...

Optimizing row performance for Angular grids in the Chrome browser

When creating a component that includes a table with numerous rows, everything works well with small amounts of data. However, once the item count reaches 2000 or more, it starts lagging. Scrolling and animations become sluggish. Even after trying to impl ...

Effortlessly alternate between dual-column and single-column layouts using CSS

Creating a basic two column layout with fixed widths is my current project. <div id='box'> <div id='ontop'>Ontop</div> <div id='column1'>Column1</div> <div id='column2'&g ...

Having trouble with aligning items in the center using Bootstrap 5?

Can anyone help me figure out how to center a div or img element vertically within another div element? I've tried using align-items-center", but nothing seems to be working. I've also experimented with changing the display properties of both ele ...

What is the best way to customize the appearance of Image tags located inside SVGs, whether they are in separate files or embedded within the code

I am developing a custom SVG editor application and facing an issue with implementing a highlighted effect when an <image> element is clicked. I have successfully accomplished this for other elements like <circle> by adjusting attributes such a ...

What obstacles may hinder the loading of CSS with PHP variables?

Visit this website for agriculture updates: I have utilized PHP to generate specific color schemes and styles. It seems to function correctly on all tested desktop laptops, however, it fails to load the CSS files (only loads HTML) on a Galaxy Note runnin ...

Arranging elements on top of a fixed element using JavaScript and CSS

Currently, I am implementing Javascript code that adds a div to the body of pages. The purpose of this div is to always stay at the top of the document or window, regardless of the page's design and content. Everything was functioning correctly until ...

Updating $scope variables in AngularJS for real-time refreshing in the HTML

Is there a way to automatically trigger my variable in the $scope object? //controller setInterval(function(){$scope.rand=Math.random(10)},1000); //template {{rand}} I am having trouble updating the 'rand' variable on my page. What is the solu ...