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
  • 6036 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

     

    It's doing what I wanted it to do in every browser and device I've tested so far. 

    I am sorry if I did anything to upset you, you sound upset by this conversation. 

    We are just a small business and I do a wide variety of things here, many that don't have anything to do with code, so I am far from an expert, and just appriciate learning whenever I can. Thanks again! 


    quote

     

    It's doing what I wanted it to do in every browser and device I've tested so far. 

    I am sorry if I did anything to upset you, you sound upset by this conversation. 

    We are just a small business and I do a wide variety of things here, many that don't have anything to do with code, so I am far from an expert, and just appriciate learning whenever I can. Thanks again! 


    By @acobbcarthagemills

     

    No, you didnt do anything to upset anyone. We are just having a healthy debate about some minor inclusions in the code as to if its strictly necessary or not. Either way it isnt going to make any difference. Page is working just fine, although when I looked at it a few hours ago there was a few code errors. You have a few duplicated opening anchor tags which should not be there but don't seem to be making the browser throw a wobbly.

     

     For instance (in bold)

     

    <a href="<a href="https://carthagemills.com/stormwater-erosion-control-products.php"><u>Stormwater Products and BMPs</u></a>

     

    I think there are a few more duplicates.

     

    You also dont need the <u></u> tag when the link text is wrapped in an anchor tag as that is underlined by default.

    Nancy OShea
    Community Expert
    Community Expert
    July 8, 2022

    You have 3 options:

     

    Hope that helps.

     

    Nancy O'Shea— Product User & Community Expert