Home > Web Front-end > CSS Tutorial > How to Reorder Bootstrap Columns Differently on Mobile vs. Desktop?

How to Reorder Bootstrap Columns Differently on Mobile vs. Desktop?

Barbara Streisand
Release: 2024-11-22 08:07:10
Original
702 people have browsed it

How to Reorder Bootstrap Columns Differently on Mobile vs. Desktop?

Responsive Layout with Column Order Modification in Bootstrap

In web development using Bootstrap, there may arise a need to reorder columns differently on mobile devices compared to larger screens. This question explores a scenario where the column order is desired to switch from 1-3-2 on the desktop version to 1-2-3 on the mobile version.

Bootstrap 4 employs flexbox for layout, which typically results in equal heights for columns. This feature poses a challenge in achieving the desktop layout desired in this case. To circumvent this, one approach is to disable flexbox on larger screens (e.g., LG) and utilize floats to enable natural alignment of columns.

Here's an example code that incorporates this approach:

<div>
Copy after login

How it Works:

  • Columns are maintained in the same row, as the order is relative to the parent row.
  • d-flex and d-lg-block disable flexbox on LG screens and larger.
  • float-left aligns columns to the left when flexbox is disabled.
  • order-* reorders columns when flexbox is enabled on mobile devices.

Another option is to explore flexbox wrapping hacks involving w-auto. However, the solution presented above offers a straightforward means of achieving the desired column order in Bootstrap.

The above is the detailed content of How to Reorder Bootstrap Columns Differently on Mobile vs. Desktop?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template