Flexbox wrap allows you to determine which child element will move to the next line

Is there a way to control which child element in flexbox drops to the next line, instead of just the last one every time? For example: Full-size, no breaking: https://i.sstatic.net/proUB.png

Default behavior, breaking the last element: https://i.sstatic.net/lOfR9.png

Preferred behavior, breaking the div from the middle to the next line: https://i.sstatic.net/SAV9Y.png

Can this be achieved using flexbox?

Answer №1

Utilizing the <code>column property is a great way to achieve equal width elements

.container {
  column-width:max(30vw,150px);
}

.container > div {
  padding:10px;
  width:100%;
  display:inline-block;
  border:1px solid;
  margin-bottom:5px;
  box-sizing:border-box;
}

/* Ensure correct layout for additional elements */
.container > i {
  display:block;
}
<div class="container">
  <div>A</div><i></i>
  <div>B</div><i></i>
  <div>C</div>
</div>

Answer №2

Modified: Utilize the order: n; property to arrange flex items and the flex shorthand property to ensure the b element takes up the full width with flex: 0 0 100%. Adjust the order by setting order: 2

.flexbox {
  display: flex;
  flex-wrap: wrap;
}

.a, .b, .c {
  flex: 1;
}

@media(max-width: 768px) {
  .b {
    flex: 0 0 100%;
    order: 2;
  }
}
<div class="flexbox">
  <div class="a">A</div>
  <div class="b">B</div>
  <div class="c">C</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

Tips for validating email addresses and enforcing minimum length requirements

In order to validate email input for the correct format and ensure minimum length validations for first name and password, I am looking to utilize only bootstrap. While I have successfully implemented required field validations for the inputs, I am unsure ...

Acquiring the index of a selector event within a list of dynamic elements

I am seeking guidance on how to go about solving the issue of obtaining an event index. I have a hunch that closures might play a role in the solution and would appreciate some insights. Initially, I dynamically build an HTML5 video container using an aja ...

Locating the save directory with fileSystem API

I've been working on saving a file using the fileSystem API. It appears that the code below is functional. However, I am unable to locate where the saved file is stored. If it's on MacOS, shouldn't it be in this directory? /Users/USERNAM ...

Tips for setting the tabindex on an element that has an opacity of 0

I have created a drag and drop image upload field with a hidden input element to style the upload button according to the design. However, I am concerned about accessibility and want the upload functionality to trigger when the user presses 'Enter&apo ...

Using CSS to break or wrap long words in text

I have a div that spans the width of the page. I'm looking to ensure that a very long word in this div breaks and wraps properly, so all the content stays within the screen width and doesn't overflow beyond 100%. Although I've attempted usi ...

Save user entries in a database array

I'm working on developing a platform for advertisements where users can create detailed profiles with images. To achieve this, I need to store the information in an array within a backend database for future retrieval. Below is an example of the backe ...

What is the best way to customize the lower border color of a collapsed Bootstrap navbar with an inverse design

Discussing this issue.. I am noticing two distinct colors. One is darker than the background shade and the other is lighter than the background shade. How can these be set? https://i.sstatic.net/Y39IZ.jpg <nav class="navbar navbar-inverse"> <d ...

Positioning pictures in front of a backdrop

I'm facing an issue with a section that slides into view with a blue background. I want to add a picture in the upper left corner, but it's barely visible and the blue background disappears. Here's a snippet of the HTML code: <header id ...

Tips for customizing the CSS file of a React component imported from a UI framework

As I embark on building a large application utilizing React, I find myself navigating the new territory of React philosophy coming from a background of Css+Js+jQuery methods. One key requirement for my project is a reliable UI framework that aligns with Go ...

Enable contenteditable on table by pressing the tab key

I developed a table entry tool and I would like to be able to input items by pressing the tab key instead of having to manually click on each element. I haven't been able to figure out how to make this function work yet. $('table').on(&apos ...

How can I locate the input field using XPath that is positioned next to a

I am having difficulty targeting a checkbox located next to a label with a specific name that includes an underscore character. Here is an example of the DOM structure: <div id="form-2143"> <div id="wrap-1353"> <label id="numberfield ...

Transferring information from various HTML forms using JQuery's ajax functionality

Hello there! I have recently started learning how to use jQuery AJAX for file uploads. Currently, I am working with a simple HTML form and including JavaScript/jQuery code within it to make an AJAX request. <!DOCTYPE HTML> <html> <head> ...

Using Bootstrap 5 to beautifully wrap an even quantity of boxes

My challenge is to optimize the spacing between 4 boxes based on screen size: The layout should adjust as follows: If it's xxl or larger, all 4 boxes should be in a single horizontal row. If it's md or larger, two boxes should be in the firs ...

Tips on adjusting the color of a link once it has been clicked?

Looking for a link with a specific style? a { color: #999; &:hover { color: #008da0; } &:visited { color: #999; } /* I added this to test if it's gonna fix it, but it didn't */ } Upon clicking the link, it turns blue and remains s ...

Glitch Uncovered in Excel Spreadsheet I Exported

I have a situation where I am working with an HTML table that includes both text and radio buttons. The issue arises when I attempt to export the table data along with the selected radio button values to Excel using the 'Export to Excel' button. ...

matching patterns within HTML div elements

Within my Notepad++ text editor, I am attempting to remove all spaces within a div tag except for those between the comma and the last name. This is what the input looks like: <div class="n"> Joe , Williams </div> And this is the desire ...

Is it advisable to incorporate CSS variables in place of traditional HTML color names?

As an illustration, I frequently utilize the color white in my CSS code. :root { --color-white: #fff; } I am curious if it is beneficial to define colors such as 'black' and 'white' as variables or if I should stick to using the def ...

What is the best way to unselect the "all" selector if one of the inputs is no longer selected?

I am facing an issue with a search filter functionality. When all filters are selected and then deselected individually or together, the "all" button remains selected. I need help in ensuring that when any filter is deselected, the "all" button also gets d ...

Error Message: "Issue with jQuery mobile: Uncaught TypeError - Unable to read property 'abort' of undefined during AJAX request"

Hey there, I recently created a website using jQuery Mobile and implemented the autocomplete feature. However, I encountered an error message saying Cannot read property 'abort' of undefined. Here is the code snippet: <div id="myPage"> ...

Disabling GPS with HTML5/phonegap: A step-by-step guide

Looking to create a function that can toggle GPS on and off for both iPhone and Android devices ...