Skip to main content
Known Participant
July 8, 2022
Answered

Side By Side Images Responsive - 3 Columns Desktop to 1 Column on Mobile

  • July 8, 2022
  • 2 replies
  • 5958 views

I need html and css for a simple page that will have 3 images with text centered underneath each image, side by side on desktop, that goes to 1 column on mobile devices. So 3 columns to 1 column. Can anyone help? Has to be .php file to work with our site if that matters. I will use the existing header footer code for our site, and put this html code into the body. I looked at templates in Dreamweaver, and they were not helpful to me.

Thanks! 

    This topic has been closed for replies.
    Correct answer Nancy OShea

    I'm going to cut to the chase and use CSS GRIDS because it does exactly what you want without media queries.  And it will work with any number of items.

     

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>CSS Grid Evenly Distributed Layout</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
    body {
    width: 95%;
    margin: 0 auto;
    padding: 2%;
    }
    .grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    grid-auto-rows: minmax(150px, auto);
    grid-gap: 1em;
    border: 1px dotted silver;
    }
    .module {
    background: #eaeaea;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    }
    </style>
    </head>
    
    <body>
    <h3>Welcome to CSS Grids</h3>
    <div class="grid">
    <div class="module">1</div>
    <div class="module">2</div>
    <div class="module">3</div>
    <div class="module">4</div>
    <div class="module">5</div>
    <div class="module">6</div>
    <div class="module">7</div>
    <div class="module">8</div>
    <div class="module">9</div>
    <div class="module">10</div>
    <div class="module">11</div>
    <div class="module">12</div>
    <div class="module">13</div>
    <div class="module">14</div>
    <div class="module">15</div>
    </div>
    </body>
    </html>
    

     

    2 replies

    Nancy OShea
    Community Expert
    Community Expert
    July 8, 2022
    Nancy O'Shea— Product User & Community Expert
    Known Participant
    July 13, 2022

    Ok, here is my testing page - this goes from 3 columns to 1 column the way I want it to, but I want it to go to 2 columns before it goes to 1 (so I need to add an inbetween). I think it will go right above this code but not quite sure what to add, can you please help?

     

    /* Responsive layout - makes a one column-layout instead of two-column layout */
    @media (max-width: 800px) {
    .flex-container {
    flex-direction: column;
    }
    }

    Legend
    July 21, 2022

    When this discussion started there was no layout to speak of.  We gave the OP an empty grid as a starting point.  And here we are 12 days later... 

     

    Min-height = no less than.

    Height = equal to.

    Max-height = no more than.

     

    Product evolution:

     


    quote

    When this discussion started there was no layout to speak of.  We gave the OP an empty grid as a starting point.  And here we are 12 days later... 

     

    Min-height = no less than.

    Height = equal to.

    Max-height = no more than.

     

    Product evolution:

     

     


    By @Nancy OShea

     

     

    You're stating the bl**dy obvious what they mean, not why you feel the necessity to use it when it actually is redundant in this particular instance. Given the images are responsive and could be any height considering the numerous screen sizes they would be viewed on.

     

    I actually cant think of too many instances where min-height would be of much use, maybe apart from keeping a comment input box to a minmum. Im sure its a useful addition to have in the tool kit so it can be used when and where necessary, I personally just can't see it is in the situation we are discussing. 

     

     

    Nancy OShea
    Community Expert
    Community Expert
    July 8, 2022

    You have 3 options:

     

    Hope that helps.

     

    Nancy O'Shea— Product User & Community Expert