Quantcast
Channel: Active questions tagged flexbox - Stack Overflow
Viewing all articles
Browse latest Browse all 1320

Without media queries how to achieve 3 column desktop to 1 column mobile layout

$
0
0

Looked into a few questions here but they don't quite solve what I'm looking for.

Say I have a website and I want. On desktop I want this:

enter image description here

This is easy. grid-template-columns: repeat(3, 33%) (basically)

On mobile, however, I want this

enter image description here

What I'm running into is happens before it flips to a single column:

enter image description here

I'm trying clamp(), minmax(), and all sorts of things but nothing ever works as I want. Yes, I can totally use a media query but I was hoping to create a truly fluid grid/flex layout using modern CSS like clamp, grid, minmax, etc so there wouldn't be a need for media queries for basic layout changes.

I know this doesn't work but as a starting point as requested here's a simple version of one of my 100 attempts :) In this version I was trying to use clamp to switch from a repeat(3) to repeat(1).

.wrapper {  display: grid;  gap: 15px;  grid-template-columns: repeat(clamp(1, calc(100% - 500px), 3), 33%);}.one {  background: red;}.two {  background: green;}.three {  background: blue;}
<div class="wrapper"><div class="item one"><h3>Example A</h3></div><div class="item two"><h3>Example Two</h3></div><div class="item three"><h3>Third Example</h3></div></div>

Viewing all articles
Browse latest Browse all 1320

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>