The flex order in my responsive layout with three columns is not being honored

I'm trying to create a three-column layout on my website using flexboxes.

However, the 'commentCaMarche' div is not behaving as expected and is appearing at the top of the 'details-index' column. Any ideas on how to fix this issue?

#credits {
    font-family: 'Roboto Condensed', sans-serif;
    color: #FFFFFF;
    height: 100vh;
    background-color: #FB3D00;
    margin-bottom: 0;
}

#columns {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
}

#details-index {
    font-size: 1.6vmin;
    text-align: center;
    flex: 1;
    order: 1;
    display: flex; /*Note : Each of my columns is also a flex container for other contents I omitted*/
    flex-direction: column;
    justify-content: space-around;
}

(...)

#commentCaMarche {
    font-size: 2vmin;
    text-align: center;
    flex: 1;
    order: 2;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
}

(...)

#sources {
    font-size: 1.4vmin;
    text-align: center;
    flex: 1;
    order: 3;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
}
<div id='credits'>
    <div id='columns'>
        <div id='commentCaMarche'>
            <h2>How it works</h2> (...)
        </div>
        <div id='details-index'>
            <h2>The Details</h2> (...)
        </div>
        <div id='sources'>
            <h2>Data Sources</h2> (...)
        </div>
    </div>
</div>

Answer №1

Below is the CSS code snippet to create a responsive layout with 3 columns:

#columns{width:100%; float:left;}
#commentCaMarche{width:33.33%; float:left}
#details-index{width:33.33%; float:left}
#sources{width:33.33%; float:left}

Answer №2

To adjust the layout of your flex columns, you will need to update the order property. Refer to this JSfiddle link for more details.

#details-index {
    font-size: 1.6vmin;
    text-align: center;
    flex: 1;
    order: 2;
    display: flex; /*Please note that each column is a flex container as well, which I have not included here*/
    flex-direction: column;
    justify-content: space-around;
}

#commentCaMarche {
    font-size: 2vmin;
    text-align: center;
    flex: 1;
    order: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
}

Answer №3

Using the flex-wrap: wrap property will cause your columns to break onto a new line if they exceed the available width. By removing this from the columns rule, you can ensure that there are always 3 columns displayed properly regardless of the screen width.

I have also temporarily removed the order property from the flex items so that they appear in the same order as in the markup. However, if you need to change their order as in your example, you can add it back or simply rearrange them in the markup itself.

#credits {
  font-family: 'Roboto Condensed', sans-serif;
  color: #FFFFFF;
  height: 100vh;
  background-color: #FB3D00;
  margin-bottom: 0;
}

#columns {
  display: flex;
  justify-content: space-between;
}

#details-index {
  font-size: 1.6vmin;
  text-align: center;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}

#commentCaMarche {
  font-size: 2vmin;
  text-align: center;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}

#sources {
  font-size: 1.4vmin;
  text-align: center;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}
<div id='credits'>
  <div id='columns'>
    <div id='commentCaMarche'>
      <h2>Comment ça marche</h2>
      (...)
    </div>
    <div id='details-index'>
      <h2>Le détail</h2>
      (...)
    </div>
    <div id='sources'>
      <h2>Sources des données</h2>
      (...)
    </div>
  </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

The <h1> element is not responding to the style attribute

Exploring HTML as a beginner has led me to an interesting issue. I've been practicing my newfound skills on W3Schools' platform and everything was running smoothly until I encountered a discrepancy in how the code is rendered on Wordpress. The s ...

Update of a window occurs automatically

When a user clicks a link on a web page, I open a new window. $('#visit').click(function () { window.open(getHostName() + "/visits" , 'VisitsReport'); }); Within the web page $(document).ready(function () { var initializeVis ...

When incorporating an array into a span tag, only the final string is being shown by the loop

I need assistance with changing the content of a span tag every 1.5 seconds, but currently it only displays the final word in the 'list' array. Below is my JavaScript code: var list = [ "websites", "user interfaces" ]; setInterval(fun ...

Incapable of stacking one canvas on top of another

I'm new to javascript and looking for help with positioning a canvas element behind another. The code I have may be a bit messy, so any assistance is greatly appreciated. My goal is to have the canvas named "myCanvas" appear behind "coinAnimation". Th ...

The CSS property :read-only is used on elements that do not have the readonly attribute

Could someone please clarify why the CSS pseudo class :read-only is being added to elements that are not actually readonly? To see an example, check out this link I have tested this in recent versions of Edge, Chrome, and Firefox. All of them apply the i ...

MUI Datepicker options for selecting dates

Is there a way to selectively enable certain dates and disable all others in the MUI Datepicker? For example, I need to only allow dates that are 7 days later or earlier to be selectable, while all other dates should be disabled. How can this be achieved? ...

Tips for removing a section of HTML code within a PHP script

I attempted to remove a "Search" button located in the top left corner of a website. While searching for a solution, I stumbled upon a helpful tip at this link: Best way to find out which php file has generated an html line of code in WordPress Even afte ...

Selenium RC: Utilizing the CSS :contains pseudo-class for Element Selection

I have a task to verify that the data in a table row matches my expectations for two different tables. Let's look at an example using HTML: <table> <tr> <th>Table 1</th> </tr> <tr> <t ...

What is the best way to smoothly switch from one Font Awesome icon to another?

I am working on an HTML button with the following code: <button id="sidebar-toggle-button" class="btn btn-primary header-btn" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasExample&q ...

"Interactive demonstration" image toggle through file upload

I have a project to create a "demo" website for a client who wants to showcase the template to their clients. A key feature they are interested in is allowing users to upload their logo (in jpg or png format) and see it replace the default logo image insta ...

What is the best way to transfer form data stored locally to a Django view and then store it in the database?

Is there a way to transfer form data from an offline website to a Django view for database storage? I want to fill out a form, save it in local storage, and then upload the data to the database when I reconnect to the internet. Is there a tutorial or can ...

Sending Data Between Web Applications in JavaScript

Currently developing a take-away application using AppLab, which uses JavaScript. Due to the limitations of modifying HTML code in AppLab, I had to utilize an external web app for the checkout process (unable to integrate PayPal buttons in AppLab). When th ...

Disappear from Sight: Content Concealed as Window Size Changes

Struggling with resizing text and buttons on a website built from a template for class. Looking to ensure that the text remains visible even when the window size changes. Ideally, I want the page content to stay anchored so the focus remains on the text/b ...

Embed the div within images of varying widths

I need help positioning a div in the bottom right corner of all images, regardless of their width. The issue I am facing is that when an image takes up 100% width, the div ends up in the center. How can I ensure the div stays in the lower right corner eve ...

Transfer the information from dropped files in a div to a separate page

document.getElementById('drag_drop').ondrop = function(event) { event.preventDefault(); var form_data = new FormData(); var drop_files = event.dataTransfer.files; for(var count = 0; count < drop_files.length; count++) ...

Styling: How can I create indentation for a specific text area while leaving another unaffected?

I am attempting to format this complete form with an indentation: <%= form_for([micropost, micropost.comments.build], :html => { :id => "blah_form" }) do |f| %> <div class="field"> <p2>Who are you?</p2> ...

Error message: ASP.Net Update Panel unable to access global variables in code-behind

I have been working on updating a bootstrap progress bar's percent on my website. While I understand that ajax is the recommended method for this, I attempted to achieve this without using ajax and was able to make some progress. Below is the code sn ...

Is there a way to deactivate a button in Angular when an <input> field is blank, without relying on form validation?

Looking for a way to utilize @output in Angular, I have set up an input field with a button. The goal is to send the input field data to the parent component using @output(). My challenge is to disable the button if the input field is empty, without relyin ...

Can an HTML page be created where certain elements cannot be targeted using CSS selectors or XPaths?

To put it differently: Do any HTML structures restrict the selection of elements using CSS selectors? Do any HTML structures restrict the selection of elements using XPaths? Appreciate it! :) ...

I am looking to design a pair of Carousels that will be positioned right next to

Is it possible to set up two Carousels next to each other? https://i.sstatic.net/Dv7PB.png <div class="row"> <div class="col-md-2"></div> <div class="col-md-8"> <div id="Carousel" class="carousel slide"> ...