By utilizing the "order" property, I can arrange divs to start at the bottom and ascend as additional elements are added

Exploring the use of display: flex and order:, I noticed a curious behavior. When I set the order for my first div to 0 (order: 0;), it appears at the top of the page. However, as I add more divs with different orders, they initially show up in unexpected positions on the page. Strangely enough, the elements gradually correct themselves and align correctly as I continue adding more divs to the order property.

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

.box {
  width: 100%;
  height: 100px;
  text-align: center;
}

.lime {
  width: 100%;
  order: 0;
  background-color: lime;
}

.red {
  width: 50%;
  order: 1;
  background-color: red;
}

.orange {
  width: 50%;
  order: 2;
  background-color: orange;
}

.teal {
  width: 100%;
  order: 3;
  background-color: teal;
}

.light_blue {
  width: 20%;
  order: 4;
  background-color: lightblue;
}

.dark_blue {
  width: 60%;
  order: 5;
  background-color: darkblue;
}

.green {
  width: 20%;
  order: 6;
  background-color: green;
}
<body>
  <div class="container">
    <div class="box lime"></div>
    <div class="box dark_blue"></div>
    <div class="box light_blue"></div>
    <div class="box green"></div>
    <div class="box red"></div>
    <div class="box orange"></div>
    <div class="box teal"></div>
  </div>
</body>

I am left wondering why this behavior occurs and why everything falls into place only after including the final

.green {width: 20%; order: 6; background-color: green;}
in my CSS?

Answer №1

Your code is functioning as expected, but it only starts working correctly after setting the order:6. Prior to that, the default value for the element was order:0.

Keep in mind, when using the order property:

By default, flex items are displayed in the order they appear in the source. However, the order property allows you to control their visual order within the flex container.

To simplify your usage of the order, consider utilizing values like 4, 5, and 6 within the same elements where it's applied.

body {
  margin: 0
}

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

.box {
  height: 100px;
}

.lime {
  background-color: lime;
}

.red {
  background-color: red;
}

.orange {
  background-color: orange;
}

.teal {
  background-color: teal;
}

.light_blue {
  order: 4;
  background-color: lightblue;
}

.dark_blue {
  flex: 0 60%;
  order: 5;
  background-color: darkblue;
}

.green {
  order: 6;
  background-color: green;
}

.fifthish {
  flex: 0 20%
}

.half {
  flex: 0 50%
}

.full {
  flex: 0 100%
}
<div class="container">
  <div class="box lime full"></div>
  <div class="box dark_blue"></div>
  <div class="box light_blue fifthish"></div>
  <div class="box green fifthish"></div>
  <div class="box red half"></div>
  <div class="box orange half"></div>
  <div class="box teal full"></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

Ensuring WCAG Accessibility Compliance - mandate the inclusion of at least one input in a fieldset

I'm working on a form where users need to provide at least one contact method from a group of fields, such as home, work, or mobile phone number. How can I ensure this meets the latest WCAG 2.2 standards? <!-- Other fields above and below --> ...

Troubleshooting: Inline Styles not displaying Background Div Images in Next.Js

I am currently attempting to display images in a component by using a map and an external JS file to store the images as objects. I then loop through them to set each one as a background image for every created div. However, it seems like my current implem ...

Tips for avoiding anti-aliasing of bitmap font on Internet Explorer and Firefox

I am currently experiencing issues with font smoothing when using a basic bitmap font for icons. While the font appears crisp in Chrome, it appears blurry in IE and FF. Do you have any recommendations on how to resolve this problem? You can view a screen ...

Is it possible to change the background color of the scrolling page?

Let's say I have 10 different sections, each with a unique background color assigned to them. As the user scrolls down from section 1 through 10, my goal is to dynamically change the body tag's background color based on which section is currentl ...

The function in jQuery that can be used to hide a <div> when clicked

I am facing a problem with my jQuery code that is supposed to remove/hide a specific div. Despite checking various examples, I can't seem to make it work properly. This issue arises in the context of jQuery on Drupal 7. The live site where this proble ...

Tips on retaining label names for input boxes

Check out this Plunker example. I am trying to figure out how to keep labels on top of textboxes in this Plunker. Can anyone help me with that? <a class="btn btn-success btn-xs" data-nodrag ng-click="toggle(this)"><span class="glyphicon" ng-clas ...

Issues persisting with vertical alignment in table cells on Firefox browser

I've successfully managed to vertically center the contents of .onesizechart in Chrome and Safari, but I'm facing issues with Firefox and IE. Interestingly, the contents of .homepage-sizechart are displaying correctly, leading me to believe that ...

Which file is the optimal placement for the Bootstrap directory: 'header.php' or 'function.php'?

Having dabbled in WordPress Theme templates for a while, I've decided to try my hand at creating a theme from scratch. After uploading the Bootstrap features onto my server, I'm pondering whether it's better to call the Bootstrap.css files ...

What could be causing the lack of downward rotation of my arrow in css? (specifically, the span element)

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=de ...

The CSS3 feature is not compatible with the Android browser, causing issues with loading responsive CSS

Currently, I am conducting testing on my website across various mobile devices. So far, the site functions perfectly on iOS devices but encounters issues when viewed on Android devices - it appears zoomed in and fails to be responsive. Within the <head ...

How to capture text outside of a HTML tag using Selenium with Python?

I need help extracting the specific text inside a div element that is not enclosed by a label. <div style="color:red;"> <label> Total Amount Due:</label> $0.00 </div> Only interested in retrieving the $0.00 amount from th ...

Customized style sheets created from JSON data for individual elements

One of the elements in the API requires dynamic rendering, and its style is provided as follows: "elementStyle": { "Width": "100", "Height": "100", "ThemeSize": "M", "TopMargin": "0", " ...

conceal only a few HTML elements

When a user enters text into my comment box, it is saved in the database with additional formatting. For example: aa @Martins <aabb> The saved version in the database looks like this: aa <span class="highlight" contenteditable="false">@Marti ...

What specific quirk in Firefox is responsible for this behavior, and is there a way to replicate it in standards mode?

In Firefox, this particular document displays differently in standards mode compared to quirks mode. When in quirks mode, the div fills the entire screen, but in standards mode it does not. I went through the MDN quirks list and couldn't pinpoint a sp ...

Material User Interface, MUI, Modal, Back to Top Scroll按钮

After spending some time experimenting with scrollTop and the Dialog component (a fullscreen fixed modal) from Material-ui, I found that I couldn't quite get scrollTop to function properly. Whenever I clicked the "go down" button, it would either retu ...

Issue with iPad Pro displaying Bootstrap 4 Navbar toggle icon

Having trouble with my Bootstrap 4.1.1 navbar on iPadPro. It's not displaying the correct data from the div and it's not collapsing properly. However, it works fine on small devices. Any suggestions on how to fix this issue? Here's the code ...

Symbol '%' is not supported in Internet Explorer

My experience with IE versions 8 and 9 has been that they do not recognize the &percnt; entity. I have tested this on two different computers. I found information suggesting that it should be supported in IE here: http://code.google.com/p/doctype/wiki ...

Creating a layout with 2 rows and 5 columns in Bootstrap 5 may not perfectly fit a 100% width and 100% height

Can someone assist in adjusting this Bootstrap 5 code to perfectly fill the entire screen of all 16:9 devices (mobile and desktop/1080p/2160p using Chrome browser) with 100% width and height? The goal is to eliminate horizontal and vertical scrolling. Desp ...

What is the best way to add padding or margins to the heading that is being shown as a table-cell?

After finding an example for a header with lines on the side (source here, specifically: here), I've managed to implement it successfully. However, I am facing a challenge when trying to add some padding to both sides of the text and having the lines ...

Ways to align two elements within the same level in the DOM?

Is it really impossible to have two elements render parallel to each other on the z-axis? Even with the same z-index, they are treated as being on different levels based on their order in the DOM. This can be a challenge when trying to display nearby eleme ...