Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
12,989 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
12,989 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