Table row with CSS flexbox wrapping

I have a unique set of items, each consisting of:

  • A left side that expands horizontally to occupy the space where the item name is located.
  • A right box at the end containing a few actions.

My goal is to ensure that the box with actions on the right wraps when it clashes with the text on the left. The challenge lies in the varying sizes and names of different items. Is there a way to standardize the size of the left side similar to tables?

I want to maximize the text display, so it would be ideal to find a solution where once one row wraps, the others follow suit.

Below is a basic sketch illustrating my objective:

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

Additionally, here's a sample implementation of what I currently have, which wraps but not simultaneously:

.Box {
  padding: 1rem
}

.Row {
  align-items: stretch;
  display: flex;
  flex-wrap: wrap;
}

.Fill {
  flex: 1 1 auto;
}
<div class="Box">
  <div class="Row">
    <div class="Fill">
      <span>Some text not too big</span>
    </div>
    <div>
      <span>Same width</span>
    </div>
  </div>
  <div class="Row">
    <div class="Fill">
      <span>Some text that will be absolutely big for real</span>
    </div>
    <div>
      <span>Same width</span>
    </div>
  </div>
</div>

Answer №1

Here is a suggestion:

.con{
  display:flex;
  flex-wrap:wrap;
  
}
.left{
  background-color:red;
  flex:1 1 auto;
}
.right{
  background-color:blue;
  width:300px;
}
<div class="con">
  <div class="left">lskjf aölkfj aölfkj sdöflkja faölkfj aölkfj aöslkf jasölfkj saöflkas fölkas fösadkfh salökh fsllfkj sdöflkja faölkfj aölkfj aöslkf jasölfkj saöflkas fölkas fösadkfh salökh fsllfkj sdöflkja faölkfj aölkfj aöslkf jasölfkj saöf saöflkas fölkas fösadkfh salökh f</div>
  <div class="right">003</div>  
<div class="left">lskjf aölkfj aölfkj sdöflkja faölkfj aölkfj aöslkf jasölfkj saöflkas fölkas fösadkfh salökh fsllfkj sdöflkja faölkfj aölkfj aöslkf jasölfkj saöflkas fölkas fösadkfh salökh fsllfkj sdöflkja faölkfj aölkfj aöslkf jasölfkj saöf saöflkas fölkas fösadkfh salökh f</div>
      <div class="right">004</div>
    </div>

You might want to consider adding flex-wrap:wrap to the container and giving a specific width to the right or action-oriented divs.

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

Content missing after centered banner

Seeking help! I need to figure out how to center text after a container. Whenever I try, it ends up either behind the banner picture or misaligned. I want both the banner and the text example to be centered, but placing the text in the right position has b ...

Using jQuery to load and parse a JSON file stored on a local system

I am a beginner in scripting languages and recently searched for ways to load and parse JSON files using jQuery. I found helpful resources on Stack Overflow. The JSON file I am working with is called new.json. { "a": [ {"name":"avc"}, ...

"Differences can be observed in the behavior of "this" keyword in JavaScript across different browsers,

In my code, there is a function called toggleContent() which performs the following actions: function toggleContent() { var parent = this.parentElement; toggleClass(parent,"detailsAreVisible"); } When a user clicks on a specific button, this fun ...

<a> slightly off-centered horizontal alignment

I've been trying to center a link using different methods like text-align:center and display:inline-block, but it seems to be slightly off-center. I've attached images along with my code below for reference. Any assistance would be greatly apprec ...

Determine whether the user is scrolling the window or clicking using jQuery

Is there a way to detect scrolling or clicking using jQuery? While I can monitor these events individually (scroll or click on the page), how can I ensure that if either of them occur, the user is able to proceed to the next step? ...

Issue with Navbar Collapse Toggle not deactivating (following transition from bootstrap v4 beta to v4 alpha 6)

Recently, I encountered an issue with my navbar after switching to v4 alpha 6 in order to utilize the responsive utilities that this version offered. If you visit the following page: , you will see what I mean. Prior to upgrading to v4 alpha 6, all menu ...

Having trouble with mobile support for Wordpress blockquotes?

Welcome. I am currently utilizing blockquote on my website, and it's functioning properly on desktop computers. However, there seems to be a significant issue when viewing it on mobile devices. https://i.sstatic.net/FMzVy.png Below are my current bl ...

Modify the css with JQUERY when there are no rows inside the tbody section

Is it possible to change the css using jquery if there are no rows in the table body? I have attempted this but my current approach is not working. I tried adding an alert within the if statement, but the alert did not appear. My goal is to hide the table ...

Customize the size of innerWidth and innerHeight in your THREEjs project

Is there a way to customize the size of the window where this function launches instead of it automatically calculating the height and width? I've attempted to modify this section of the code, but haven't had any success so far: renderer.setSiz ...

Using flexbox css to arrange content on the top, bottom, and right side

Just getting started with flexbox and I'm trying to position content on the top, bottom, and right side. Check out the demo However, I also need to adjust it for mobile view like the image shown below: https://i.sstatic.net/1YxtZ.png The left and r ...

Angular Material Sidenav fails to cover the entire screen while scrolling

https://i.stack.imgur.com/32kfE.png When scrolling, the Sidenav is not expanding to take up 100% of the screen and it continues to scroll along with the page content. <div layout="column"> <section layout="row" flex> <!-- siden ...

Adjust the width of the scrollbar for the <aside> section

<aside class="sidenav navbar navbar-vertical navbar-expand-xs border-0 border-radius-xl my-3 fixed-left ms-3" id="sidenav-main"></aside> Within this aside element, I have implemented a scrollbar. However, I am seeking to adjust ...

The data is not being correctly bound to Angular's ngModel

Why is my two-way binding not functioning correctly? I have imported the forms module and am using banana syntax. Even when attempting reactive forms, the issue persists. The input field is not displaying the predefined value nor updating when interacted w ...

Steps to access a unique custom drop-down menu in an upward direction

Presently, I am developing a customized AngularJS drop-down feature, which is outlined in the following HTML structure: <div> <label></label> <div> <a ng-class="{active: popover}"> <div></div> <!- ...

CSS positioning causing a performance bottleneck

Does utilizing a large amount of absolute and fixed positioning in my HTML app lead to performance degradation? Looking for insights from experienced HTML professionals. ...

Showing information from the data text option

I'm having trouble displaying text below the cube. The code works fine in a standalone fiddle, but it doesn't work when I incorporate it into my project. Can someone help me figure out how to show the value of data-text="Cube1"? Code t ...

Establishing a secure HTML5 websocket connection in a webworker on Chrome version 61

Currently, I am utilizing code to establish a secure websocket connection from a web worker. Strangely, it is functioning perfectly in Chrome 60 but encountering issues in Chrome 61. On the contrary, it works seamlessly in other browsers such as IE, Firefo ...

template not being loaded with form

My Django form is not showing up when I try to implement it. Even after checking the browser's inspector, there is no sign of it being loaded at all. If more information is required, please let me know. Here is the project structure: /beerad url ...

CSS delays affecting the loading of the page's display

I am currently working on a WordPress website and I have noticed that one of the CSS files takes approximately 10 seconds to load, causing a significant delay in displaying the page. I am looking for ways to speed up this loading process. As part of my ef ...

Displaying current location on Google maps with generated code and adding a new marker by clicking in PHP: Firefox

I am currently working on a code that will display a marker at the current location and also add a new marker whenever the screen is touched or clicked. I have been trying to make it work with the code I found online, but it has been a bit of a challenge ...