Search code examples
css-grid

How to achieve 2 equal columns on desktop and 1 column on mobile with css grid


I'd like to use css grid to have two always equally sized columns on desktop, and one column on mobile. I've been trying to use:

grid-template-columns: repeat(auto-fill, minmax())

with various settings inside minmax, but seem to end up with either 2 columns in both media, or 1 column in both.


Solution

  • if you are go to full page it will give you two column..

    check it.. maybe you are looking for this ..

    .container{
     display: grid;
     grid-gap:20px;
     grid-template-columns: repeat(auto-fit, minmax(500px , 1fr)); 
    
    }
    <div class="container">
        <div class="child">It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</div>
        <div class="child">It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</div>
    </div>