Re-ordering Columns in a CSS Grid Layout
In CSS Grid Layout, there are various techniques for modifying the order of columns to achieve specific layouts. This question explores the possibility of rearranging columns for mobile layouts, such as moving a column to the bottom while maintaining the desired column order on desktop layouts.
Solution Options:
Sample Code:
The following example demonstrates the use of the grid-auto-flow: dense function to achieve the mobile layout described in the question:
.container {
display: grid;
grid-template-columns: 15% 1fr 25%;
grid-auto-flow: dense; /* optimizes item placement */
}
With this code, the grid items will automatically be rearranged to fill the available space efficiently, resulting in the desired mobile layout.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3