Flex rows adjust to display as flex columns when viewed on tablets

Currently facing a challenge with responsive flex boxes. On desktop, I have 5 items in one row, but I need them to be displayed as 2 columns on tablets, with each column containing respective items. Additionally, 3 out of the 5 items should function as accordions (achieved through JS).

HTML:

  <div class="footer-item">
   <h3 class="mj-footer-header accordion">MENU 1</h3>
   <div class="panel">
      <div>Menu item</div>
      <div>Menu item</div>
      <div>Menu item</div>
      <div>Menu item</div>
      <div>Menu item</div>
      <div>Menu item</div>
      <div>Menu item</div>
   </div>
</div>
<div class="footer-item">
   <h3 class="maccordion">MENU 2</h3>
   <div class="panel">
      <div>Menu item</div>
      <div>Menu item</div>
      <div>Menu item</div>
      <div>Menu item</div>
      <div>Menu item</div>
      <div>Menu item</div>
      <div>Menu item</div>
   </div>
</div>
<div class="footer-item">
   <h3 class="accordion">MENU 3</h3>
   <div class="panel">
      <div>Menu item</div>
      <div>Menu item</div>
      <div>Menu item</div>
      <div>Menu item</div>
      <div>Menu item</div>
      <div>Menu item</div>
      <div>Menu item</div>
   </div>
</div>
<div class="footer-item">
   <h3>SUBSCRIBE</h3>
   <form>
      <input type="email" name="email" placeholder="Enter your email">
   </form>
   <a href="#">Subscribe</a>
</div>
<div class="footer-item">
   <h3>CONTACTS</h3>
   <div>Contact item</div>
   <div>Contact item</div>
   <div>Contact item</div>
   <div>Contact item</div>
</div>
</div>
</div>

My desktop CSS:

.box {
display: flex;
flex-wrap: wrap;
flex-direction: row;
width: 100%;
justify-content: space-between;
    }

My tablet CSS:

@media (min-width: 768px) and (max-width: 991px) {
.box {

      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
  }
  .box>* {
      flex: 1 1 50%;
  }
}

Struggling to achieve the desired layout on tablets: MENU 1, MENU 2, MENU 3 in one column (50% width) and SUBSCRIBE, CONTACTS in another column (50% width). Seeking help to create two equal columns for this layout.

Answer №1

To organize the divs in a specific order, you can utilize the order property and arrange them accordingly. Below is an example provided for your reference. While I have used ids in this example to clarify, it is recommended to employ :nth-of-child() for a more streamlined code structure.

HTML

<div class="box">
<div class="footer-item" id="test1">
                <h3 class="mj-footer-header accordion">MENU 1</h3>
                <div class="panel">
                <div>Menu item</div>
                [Additional menu items]
                </div></div>

                [Repeat structure for MENU 2, MENU 3, SUBSCRIBE, CONTACTS]

</div>

CSS

.box {
display: flex;
flex-wrap: wrap;
flex-direction: row;
width: 100%;
justify-content: space-between;
    }

@media (min-width: 768px) and (max-width: 991px) {
.box {
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
  }
  .box>* {
      flex: 1 1 50%;
  }

   #test3 {
      order:5;
    }

  #test2 {
    order:3
  }

  [Add orders for other elements]

}

I hope this explanation proves useful!

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

Exploring the Transition from React.js with Material UI to Next.js for Server-Side Rendering: A Comparison of Tailwind CSS, Material UI, and Chakra UI

Currently, I am in the process of moving my React.js application with Material UI components to Next.js for server-side rendering (SSR) while considering some UI changes. In my research, I have come across three UI frameworks: Material UI, Chakra UI, and T ...

Can you explain the meaning of 1__qem?

While looking at the default styles applied to HTML elements for Google Chrome, I came across this information on this page: p { display: block; -webkit-margin-before: 1__qem; -webkit-margin-after: 1__qem; -webkit-margin-start: 0; -web ...

Using Google-Prettify with AngularJS

I have been attempting to implement Google Prettify in my AngularJS project. It seems to be functioning correctly on the main page, but once I navigate to another route using Angular (after ng-view), it stops working properly. You can check out the plunker ...

After resizing, a div with a height of 100% will scroll upwards

I have a single-page website consisting of three sections, each spanning the entire width and height of the window. While resizing the window on the first or last section, everything adjusts smoothly. However, when I am on the second section, things get a ...

Center a specific item by aligning it with flex

I'm struggling to achieve a simple layout using flexbox, and I can't figure out how to do it. My objective is to have 3 divs aligned in a row, with the middle div (containing "short") centered. A visual representation would make it clearer: The ...

Text with gradient overlays

After successfully implementing a gradient effect on an image, I am facing the issue of it covering my text as well. I am struggling to locate the part of the code that needs to be modified in order to prevent the text from being obscured by the gradient e ...

Creating a div with a scrollbar limited to a maximum of 100% of the page size

<!-- ********************************************************************************************************************************************************** RIGHT SIDEBAR CONTENT *********************************************************** ...

What's the best way to adjust text color to black or white for maximum contrast when the background changes?

Currently, I am attempting to replicate the email element found on this website: .custom-blend-mode { mix-blend-mode: difference; } Although I have managed to make it work, it results in a change to the opposite color. Ideally, I would like it to remai ...

Feeling lost and frustrated trying to align a div with a menu in the center

I've been struggling for over an hour now to center a menu on my website. Despite trying all of Google's recommendations, I still can't seem to get it right. Could someone please point out what obvious mistake I might be making? Below is ...

What is the best way to add an external CSS file specifically for my custom Vue component?

Currently, I am working on a vue js component that I plan on uploading to npm. However, I have encountered an issue: Whenever I import a third-party CSS CDN into my component, it ends up applying the styles to the entire HTML instead of just my component ...

What are the steps to create a CSS grid like this?

Any suggestions on how to create a grid template similar to the image shown in this picture? I am looking to achieve this design without rounded borders and without any gaps between the elements. ...

Increase visibility, decrease visibility by utilizing ng-hide/ng-show and functions

As I implement the show more/show less feature, I am uncertain if achieving a smooth effect is feasible. However, I believe it's worth reaching out to this community for some creative ideas on how to make it possible. I have a list of dynamic links w ...

Animating a div's height with CSS keyframes, moving it smoothly from bottom to top

I am working on animating a grey bar from top to bottom, but now I need it to animate from bottom to top instead. You can view my current code here: http://jsfiddle.net/hrcu9e6b/3/ <div class="review-type-wrapper-v"> <div class="review-type ...

Excessive margin is preventing the navigation from being properly displayed

I am experiencing an issue with my sticky navigation bar that is enclosed in a div with 40px of margin on each side. The fixed navbar has a width of 100%, and while it correctly considers the parent's margin on the left side, it overflows on the right ...

Ensuring the text remains positioned above another element constantly

Looking to have the text float above a regular box and resize the font size accordingly? Here's what I've tried: https://jsfiddle.net/a87uo3t2/ @import url('https://fonts.googleapis.com/css?family=Share+Tech+Mono'); body { margin: ...

Integrate div columns within the content of Bootstrap tabs

Utilizing the X-tabs plugin, I have been working with Bootstrap 3 tabs and styling them as shown below: HTML : <div class='tabs-x tabs-below'> <div id="myTabContent-2" class="tab-content"> <div class="tab-pane fade in ...

Looking for a way to store data in local storage so it remains even after the page is reloaded? I tried adding a local storage function, but it doesn't appear to be

I am currently working on a project involving a work day scheduler and I am facing challenges in saving data within the schedule events, like at 8am, and making sure it persists on reload. The colored time block element that changes as hours pass in the da ...

Incorporating a pre-existing component into a Vue.JS template through an onclick event: How can this

I'm trying to enhance my template by implementing a feature that allows me to add a component simply by clicking on a button. Let me give you a glimpse of what I have in mind: The component named Draggable.vue is the one I intend to incorporate upon c ...

Tips for avoiding a split in the bootstrap navbar when collapsed

I've been searching for hours and still can't figure it out, so I'm really hoping someone can help me solve this before I embarrass myself. My goal is to create a navigation bar similar to the one on steamdb, where the search box remains vi ...

What are the steps for sending information to a PHP file and retrieving the outcome with AJAX?

Hey there! I'm looking to send data to PHP, receive the PHP result, and then display the result in an HTML div tag. Could you provide me with a sample code snippet for this? Thank you in advance and please excuse any mistakes in my English. ...