Hvis man laver et layout med 3 kolonner, hvor midterkolonne har prioritet, vil jeg gerne have denne midterkolonne til at komme først på f.eks. mobil telefon.
Jamie Marsland har demonstreret en metode med 2 kolonner. Hvor han med lidt css ændrer rækkefølgen på de to kolonner.
@media (max-width: 768px) {
.reverse-mobile {
flex-direction: column-reverse;
}
}
Metoden kan også anvendes med 3 kolonner – men så kommer 3. kolonne først …
Så jeg spurgte ChatGPT:
I have a 3 column layout built with wordpress gutenberg. Write me the CSS code so that the middle column is the first column when viewed on a mobile phone
Der svarede:
Assuming that the 3 column layout has the following HTML structure:
<div class="wrapper">
<div class="left-column">Left Column</div>
<div class="middle-column">Middle Column</div>
<div class="right-column">Right Column</div>
</div>You can use CSS media queries to swap the order of the left and middle columns on mobile devices. Here’s the CSS code:
/* Default styles for desktop devices */
.wrapper {
display: flex;
flex-wrap: wrap;
}
.left-column {
flex: 1;
}
.middle-column {
flex: 2;
}
.right-column {
flex: 1;
}
/* Media query for mobile devices */
@media (max-width: 768px) {
/* Swap the order of the left and middle columns */
.left-column {
order: 2;
}
.middle-column {
order: 1;
}
}In the media query, we use the
orderproperty to swap the order of the left and middle columns. By settingorder: 2on the left column andorder: 1on the middle column, we ensure that the middle column appears first on mobile devices.Note: The
max-widthvalue of768pxin the media query is just an example. You may need to adjust this value based on your design and the specific breakpoints you are using.
Skriv et svar