Is there a way to configure flexbox so that its children wrap in a manner where several children are arranged alongside one specific child

My layout resembles a table using flexbox:

+--------------+---------------+-----------------+---------------+
|      1       |       2       |        3        |       4       |
|              |               |                 |               |
+--------------+---------------+-----------------+---------------+

When the page size decreases, I want the content to wrap like this:

+--------------+-------------------------------------------------+
|              |                        2                        |
|              |                                                 |
|              +-------------------------------------------------+
|      1       |                        3                        |
|              |                                                 |
|              +-------------------------------------------------+
|              |                        4                        |
|              |                                                 |
+--------------+-------------------------------------------------+

I attempted using flex-wrap: wrap and adjusting children widths, but it resulted in:

+-----------+--------------------------------------+
|           |                   2                  |
|           |                                      |
|     1     +--------------------------------------+
|           |
|           |
+-----------+--------------------------------------+
|                        3                         |
|                                                  |
+--------------------------------------------------+
|                        4                         |
|                                                  |
+--------------------------------------------------+

This is my current code snippet:

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

.controls {
  flex: 0 0 25%;
  max-width: 25%;  
}

.name, .artist, .album {
  flex: 0 0 75%;
  max-width: 75%;
}

@media screen and (min-width: 600px) {  
  .name, .artist, .album {
    flex: 0 0 25%;
    max-width: 25%;
  }
}
<div class="container">
  <div class="controls">PLAY</div>
  <div class="name">NAME</div>
  <div class="artist">ARTIST</div>
  <div class="album">ALBUM</div>
</div>

(JSFiddle)

I'm seeking a pure CSS solution compatible with IE11+.

Answer №1

One suggestion is to utilize a nested flex container that reorganizes items 2, 3, and 4 into a column layout on smaller screens.

Below is an example tailored to your code:

HTML

<div class="container">
    <div class="controls">PLAY</div>
    <div class="inner-container"><!-- nested flex container -->
        <div class="name">NAME</div>
        <div class="artist">ARTIST</div>
        <div class="album">ALBUM</div>
    </div>
</div>

CSS

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

.inner-container {
    display: flex;
    flex: 0 0 75%;
}

.controls {
    flex: 0 0 25%;
}

.name,
.artist,
.album {
    flex: 1;
}

@media screen and (max-width: 600px) {
     .inner-container { flex-direction: column; }
     .controls { align-self: center; }
}

View the Updated Code in Fiddle

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

Do not exceed 3 elements in a row when using Bootstrap's col-auto class

col-auto is excellent. It effortlessly arranges items by size in a row, but I need it to strictly limit the number of items in each row to a maximum of 3. Each row should only contain between 1-3 items. <link rel="stylesheet" href="https://cdn.jsdeli ...

HTML does not support the use of certain symbols

Currently, I am in the process of designing a homepage for my school project. However, I have run into an issue. The content that I want to be displayed on my homepage is as follows: "Daudzspēlētāju tiešsaites lomu spēle (Massively Multiplayer Online ...

Adjust the size of a canvas using JavaFX in an FXML file

I am encountering an issue with resizing a canvas in Javafx while using scene builder and fxml. Currently, when the user clicks on the canvas, it turns black, but upon resizing the screen and clicking on the canvas again, only the original size of the canv ...

Embedded iframe links failing to open within the designated frame

I have encountered an issue on my website where the links under the portfolio section now open in a new window instead of the intended iframe. This change occurred suddenly without any alterations to the code. Despite closely examining and trying various ...

Troubles with modal functionality in Ionic application involving ion-slide-box

Utilizing ion-slider to display images has been a seamless experience, except for one hiccup. If I navigate directly from the first full image back to the home screen, the slider ceases to function properly. To address this challenge, I have employed spec ...

Extracting information from HTML and transferring it to Javascript using jQuery

My goal is to utilize jsGrid for showcasing database data without repeating code extensively. I aim to generate separate grids for each <div> with a specific id while passing on relevant values accordingly. To clarify my objective, here's a sni ...

The font size calculation is larger than the CSS definition on the Asus Nexus 7 device

Running the website on an Asus Nexus 7 (developed in jQueryMobile), I set the font size in CSS to be 14px. However, while debugging using Chrome on my PC, I noticed that the computed size is actually 22px. Here's a snippet of the HTML code: <div ...

Maintain the grouping of elements within a div when printing in Internet Explorer 8

When printing in IE8, I'm facing an issue with keeping the "Table title" line on the same page as the <table>. Despite using page-break-inside:avoid;, there is still a page break between the table title and the actual table. My expectation is f ...

Troubleshooting Problems with React-Scroll Link Element in Navigation Bar

Having trouble implementing a hover effect on my navigation links using the Link component from the react-scroll library. The desired effect is for the links to increase in size when hovered over by using transform: scale(1.1). Unfortunately, the effect is ...

Creating multiple lines with kineticjs in a HTML5 environment can be a

Referencing the following page: KineticJS - Drawing Lines with Mouse KineticJs is effective in creating lines, shapes, and enabling drag-and-drop functionality. The provided example consistently redraws the same line, prompting the question of how to draw ...

Do not display large numbers within an HTML card

I have https://i.sstatic.net/DkowD.png this card here and displaying dynamic data inside it. The number is quite large, so I would like it to appear as 0.600000+. If a user hovers over the number, a tooltip should display the full number. How can I achieve ...

Incorporating a divider into a Material-UI MenuItem causes an additional border

I needed a way to separate the MUI MenuItem using a divider, but it resulted in an extra border around the item where the divider was placed. The highlighted section in the image shows the item that has the divider= true setting and the extra border. Is th ...

PHP is experiencing issues when trying to insert data into the database

When I run a query in phpMyAdmin such as INSERT INTO table('نچجاعجان'); it appears correctly, but when I try to insert data through my PHP page, it displays in the field like this: ÙاننناÙنعن The col ...

What is the best way to send variables through an HTTP post from a JavaScript function in one file to a separate Python function in a different location?

I have a JavaScript script that retrieves user inputs from my HTML session storage and sends them to a database. Additionally, I need to send a HTTP request to pass a JSON object containing the entries to a Python file hosted elsewhere. Can anyone suggest ...

Is there a way to make a Bootstrap grid with four columns span across two rows in the second column?

How can I create a Bootstrap grid with four columns where the second column spans two rows? Hello, I am looking for help to achieve a portfolio grid layout with 4 columns (refer image here) and have the second column span 2 rows. I plan to include images ...

Is there a way to simultaneously click on a link on one page and alter the position of a particular class on another page?

I have been working on designing two pages for a website. I am looking to use JavaScript to ensure that when a link on page 1 is clicked and the user transitions to page 2, the second tab button (btn) will have an id of "default" and receive the activate c ...

What steps can I take to stop the background image from zooming in modal view?

I noticed something strange happening when I open a modal after clicking on an image on my website. The background image seems to zoom in along with the modal, thanks to a new class called .modal-open added to the body element. This class includes addition ...

What is the optimal method for invoking a Javascript function via a hyperlink?

I'm looking to include links on my website that will activate a javascript function when clicked, and I do not want these links to be underlined. Additionally, I want the cursor to change to a standard pointer. What is the most effective way to achiev ...

Attempting to design a customized dropdown navigation feature using HTML

I am having some trouble creating a dropdown menu that functions properly. Here is the code I have written: <div> <H1><FONT="TIMES ROMAN" FONT-COLOR="BLUE" > SELECT A Subject:</H1> <select id ="dropDownId"> <!-- as ...

I encounter issues with HTML input fields becoming unresponsive whenever I attempt to apply CSS filters in IE8 for stretching the background

When I wanted to stretch a background image on my website so that it always fills the available window area regardless of resolution, I initially used background-size:cover;. Unfortunately, Internet Explorer doesn't seem to support valid CSS, so I had ...