What could be the reason for the order property failing to function on divs within a block container?

I have a single container with the CSS property display: block. Inside this container, there are 3 div elements. I attempted to order them as per my code, but it proved to be impossible due to the fact that the container itself is styled as display: block instead of display: flex.

In my specific scenario, I want these 3 divs to appear stacked vertically. That's why I initially used the block display.

You can view a demonstration of what I tried to achieve on JSFIDDLE: https://jsfiddle.net/u441j2rv/1/

Here is the HTML markup:

<div id="blockContainer">
    <div>Block A</div>
    <div>Block B</div>
    <div>Block C</div>
</div>

And here is the corresponding CSS styling:

#blockContainer{
    display: block;
}
#blockContainer div:nth-of-type(1){
  background:red;
  -webkit-order: 3;
  order:3;
}
#blockContainer div:nth-of-type(2){
  background:green;
  -webkit-order: 1;
  order: 1;
}
#blockContainer div:nth-of-type(3){
  background:blue;
  order: 2;
  order: 2;
}

Answer №1

To make this work properly, you must adjust your code as shown below.

#blockContainer {
  display: flex;
  flex-direction: column;
}
#blockContainer div {
  flex: 1;
}
#blockContainer div:nth-of-type(1) {
  background: red;
  -webkit-order: 3;
  order: 3;
}
#blockContainer div:nth-of-type(2) {
  background: green;
  -webkit-order: 1;
  order: 1;
}
#blockContainer div:nth-of-type(3) {
  background: blue;
  -webkit-order: 2;
  order: 2;
}
<div id="blockContainer">
  <div>Block A</div>
  <div>Block B</div>
  <div>Block C</div>
</div>

Answer №2

The Importance of CSS Order Property

Understanding the order property is crucial as it determines the positioning of a flexible item in relation to other items within the container.

Please keep in mind that if an element is not considered flexible, setting the order property will not produce any visible changes.

Source: examplewebsite.com

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

How to implement HTML5 Application Cache in an ASP.NET MVC4 project to enable offline functionality for a web application?

Exploring the concept of app caching in HTML5 with static content and file extensions such as index.html, theme.css, and app.js. When it comes to using MVC4 for a web app, how can we cache dynamic data obtained from an API and stored in localStorage? I a ...

Blue text with the Bootstrap class ``btn-primary`` is a

When I implement twitter bootstrap into my .aspx page, the color of the text in the btn-primary appears blue instead of white. <asp:LinkButton ID="btnConfirm" runat="server" Text="Confirm" CausesValidation="true" ValidationGroup="req" CssClass="btn btn ...

Using MaterialUI to create a GridListTile with two IconButtons

I'm working with a GridListTile and trying to add a second button, but I'm having trouble getting both buttons to display. Even though I've attempted to include two ActionIcons, only one of them is showing up. Here's the code snippet: ...

What could be causing the sudden disappearance of the button?

There is an element with the ID "alpha" that contains the text "Now I'm here...". When the button is clicked, only the text should be removed, not the button itself. <div id="alpha">Now I'm here...</div> <button type="button" oncl ...

What is the method to set an element's height equivalent to the height of the entire screen?

I attempted using height: auto;, however, it did not produce the desired outcome. Do you have any suggestions or alternative solutions? ...

Access language options in the dropdown menu using keyboard shortcuts

I have a dropdown that appears when the mouse hovers over it: Is there a way to also trigger the dropdown to appear when the user tabs to it? I've tried following this thread for guidance: Selecting div in custom dropdown using Keyboard (Up, down and ...

CSS universal selector not applying to images

I have scoured through different resources and they all seem to echo the same information. Here is the code in question: *:not(img) { display: none; } Its intended purpose is to hide everything on the page except images. However, it seems to be hiding t ...

What happens when there is a 1-second delay in loading CSS on an HTML page?

Lately, I've been working on creating HTML and CSS pages. However, whenever I load a page, I notice that there's always a brief half-second flash of the HTML content without any styling applied. Does anyone have an idea why this is happening and ...

jquery allows for creating a list with customizable options that can change dynamically

I am looking to create a list with attachments and have the responding options displayed in a content box when a user clicks on the buttons. Afterwards, I plan to save the content box as an HTML file into my database. Do jQuery plugins support this func ...

Tips for Placing a Div in a Precise Location

I'm currently working with Bootstrap and I'm attempting to replicate a layout similar to the one used by Twitter, as shown in the screenshot below. The specific part I'm struggling with is where the profile picture is located. I want to add ...

how to use jQuery to hide a flash-containing div without losing its content

Hello, I created a modal with jQuery UI that is displaying in front of a flash movie. However, the HTML content inside the modal appears corrupted. I attempted to hide the movie just before the modal is triggered and make it reappear after closing the mo ...

Is there a more efficient method for showcasing model objects in Thymeleaf rather than utilizing a form?

I've been exploring Spring Boot, Thymeleaf, and frontend development in general. Currently, I have a frontend table that displays a list of objects from the backend, along with a form to allow users to view properties of each item in the list. Howeve ...

How can I dynamically update the value of an ng-option based on the selection of another ng-option?

My application has 2 select option boxes. The first box contains a list of countries, and I want the second box to update its values based on the selection made in the first box. For instance, if I choose India from the first select box, the second select ...

Create a div element that can be expanded on smaller devices

Is it possible to expand a div while hovering on a small or x-small device? I want to achieve something like this: https://i.sstatic.net/doJKa.png Currently, I can only hide the yellow div when the page is displayed on a small device. I am looking for a ...

What is the best way to position two elements inline?

I was trying to create a container named project-item that looks like the image linked below: https://i.stack.imgur.com/6XzZ9.png My goal was to align the project logo and the title (h3) in one line, but I struggled to find a suitable solution. This is ...

Vertically Center Image in a Div

I have been struggling to center an image within a div, but all the usual methods like using margin: auto; do not seem to work. I have tried various popular techniques with no success. <style> /* Add a black background color to the top navigation ...

Guide to successfully transferring information from a Java servlet to an HTML document using VueJS

I am currently working on sending JSON data from a servlet to an HTML page that is utilizing VueJS. Here is the method I am using to pass the JSON data from the servlet: List<Projects> list = projectInfo.getProjects(); Gson gson = new Gson(); ...

The white background of the .jpg image is conflicting with the white background of the HTML

My website has a top-of-page .jpg image that was created with a white background. However, when using the img src="topOfEveryPageImage.jpg" tag, the white background of the image appears visually different from the rest of the solid white background on the ...

What causes the entire page to disappear when the screen is adjusted to mobile width?

I'm facing an issue with my ReactJS screen. Everything works perfectly until I resize the screen to mobile width (sm of Material UI) and then everything turns into a WhiteScreen. I've been trying to debug this but can't seem to find the root ...

Is there a JavaScript tool available that allows for the integration of textareas that automatically refresh the formatting of a webpage as you type?

I have a unique opportunity to teach HTML to at-risk children in an upcoming class, but our time is limited. I want to show them how fun it can be to create their own web page. My plan is to create a page template filled with text boxes that the kids can ...