Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Basics (2014) Enhancing the Design With CSS Adjusting the Layout with Media Queries

question how to go about creating containers that hold images in the middle of the page with even spacing

Im this far in css and I still dont understand how to create clickable pictures in the middle of my page like in a grid style with even spacing and stuff.

4 Answers

Blake Larson
Blake Larson
13,014 Points

Sounds like you want to look into flexbox and grid displays.

A couple ideas with flexbox:

*****Download some free images and put them in your image folder******************

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <link rel="stylesheet" href="styles.css" type="text/css" />
    <title>Document</title>
  </head>
  <body>
    <div class="container">
      <div class="img-container">
        <a href="#" class="img-link">
          <img
            src="/img/air-jordan-design-footwear-1598505.jpg"
            alt=""
            class="image"
          />
        </a>
      </div>
      <div class="img-container">
        <a href="#" class="img-link">
          <img
            src="/img/blur-classic-close-up-267294.jpg"
            alt=""
            class="image"
          />
        </a>
      </div>
      <div class="img-container">
        <a href="#" class="img-link">
          <img
            src="/img/canvas-shoes-close-up-color-1240892.jpg"
            alt=""
            class="image"
          />
        </a>
      </div>
      <div class="img-container">
        <a href="#" class="img-link">
          <img src="/img/fashion-footwear-19090.jpg" alt="" class="image" />
        </a>
      </div>
      <div class="img-container">
        <a href="#" class="img-link">
          <img
            src="/img/footwear-leather-wear-267320.jpg"
            alt=""
            class="image"
          />
        </a>
      </div>
    </div>
  </body>
</html>

(column FLEX)

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 62.5%;
}

.container {
  width: 80%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background-color: lightgrey;
}

.img-container {
  margin: 1.5rem 0;
  width: 40%;
  align-self: center;
}

.image {
  width: 100%;
}

Row (FLEX)

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 62.5%;
}

.container {
  width: 80%;
  margin: 0 auto;
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  background-color: lightgrey;
}

.img-container {
  margin: 2rem 1rem;
  width: 45%;
  height: 500px;
  align-self: center;
}

.image {
  width: 100%;
  height: 100%;
}

play around with some flex-box properties and see how it changes.

thanks so much guys I appreciate I have a butt ton of questions don't want to bombard anyone...is anyone having issues with Catalina not opening atom, kinda driving me nuts cause I like atom I'm using brackets right now.

Guys any idea why I can't see the place holder images

<!DOCTYPE html> <html> <head> <title>Real Ink Shirts</title> <link rel="stylesheet" href="style.css"> <nav id="primary-nav"> <ul> <ol>Home</ol> <ol>Contact</ol> <ol>Blog</ol> </ul> </nav> </head> <main> <body> <h1>Real Ink Shirts</h1> <h2> New England's Primer Novelty T Shirt Shop <h2> <div class="container"> <div class="img-container"> <a href="https://dummyimage.com/300.png/09f/fff" class="img-link"> <img src="/img/air-jordan-design-footwear-1598505.jpg" alt="" class="image" /> </a> </div> <div class="img-container"> <a href="https://dummyimage.com/300.png/09f/fff" class="img-link"> <img src="/img/blur-classic-close-up-267294.jpg" alt="" class="image" /> </a> </div> <div class="img-container"> <a href="https://dummyimage.com/300.png/09f/fff" class="img-link"> <img src="/img/canvas-shoes-close-up-color-1240892.jpg" alt="" class="image" /> </a> </div> <div class="img-container"> <a href="https://dummyimage.com/300.png/09f/fff" class="img-link"> <img src="/img/fashion-footwear-19090.jpg" alt="" class="image" /> </a> </div> <div class="img-container"> <a href="https://dummyimage.com/300.png/09f/fff" class="img-link"> <img src="/img/footwear-leather-wear-267320.jpg" alt="" class="image" /> </a> </div> </div> <!-- DivTable.com --> <main> </body> <footer> <ul> <ol>Home</ol> <ol>Contact</ol> <ol>Blog</ol> </ul> </footer> </html>

Blake Larson
Blake Larson
13,014 Points

If you are talking about the src attribute on the img tag I downloaded those from pexels and moved them into my img folder. Pexels. Also a heads up it looks like the footer is outside the body tag.

Thanks so much guys