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

Some wrappers won't center its content

When I am centering content I am using the div with the class "wrap". My header content will center, but the div within the section won't.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="css/normalize.css">
    <link href='https://fonts.googleapis.com/css?family=Marvel:400,700,400italic|Gentium+Basic:400,700italic,700' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="css/style.css">
  </head>
  <body>
    <header class="siteHeader">
      <div class="wrap">
        <a href="index.html" class="heading">
          <h1>WebDev</h1>
          <h2>A Design Community</h2>
        </a>
        <nav class="siteNav">
            <ul class="linkTo">
              <li><a href="#">Showcase</a></li>
              <li><a href="#">My Portfolio</a></li>
              <li><a href="#">2D</a></li>
              <li><a href="#">3D</a></li>
              <li><a href="#">Typography</a></li>
              <li><a href="#">Calligraphy</a></li>
            </ul>
          </div>
        </nav>
      </div>
    </header>
    <section class="galSection">
      <div class="wrap">
        <ul class="gallery">
          <li>
            <a href="#">
              <h2>2D Graphics</h2>
              <img src="img/img1.png" alt="">
              <p>Description of 2D Graphics</p>
            </a>
          </li>
          <li>
            <a href="#">
              <h2>3D Graphics</h2>
              <img src="img/img2.png" alt="">
              <p>Description of 3D Graphics</p>
            </a>
          </li>
          <li>
            <a href="#">
              <h2>Typography</h2>
              <img src="img/img3.png" alt="">
              <p>Description of Typography</p>
            </a>
          </li>
          <li>
            <a href="#">
              <h2>Calligraphy</h2>
              <img src="img/img4.png" alt="">
              <p>Description of Calligraphy</p>
            </a>
          </li>
        </ul>
      </div>
    </section>
    <footer>
      <p>&copy; 2016 Creativity Hub</p>
    </footer>
  </body>
</html>
* {
  box-sizing: border-box;
}

a {
  text-decoration: none;
  color: gold;
  font-weight: bold;
}

img {
  max-width: 100%;
}

body {
  font-family: "Marvel", sans-serif;
}

.wrap {
  width: 90%;
  text-align: center;
  margin: 0 auto;
}

body {
  background: linear-gradient(45deg, blue, red);
  color: white;
}

/***********************
HEADER
************************/
.linkTo {
  list-style: none;
  padding: 0;
  margin: 0;
}

.heading {
  font-size: 2rem;
}

.heading h2 {
  margin-top: -30px;
  font-size: 1.67rem;
}



/***********************
DISPLAY
************************/
.galSection {
  margin: 30px 0;
}

.gallery {
  list-style: none;
  padding: 0;
  margin: 0;
}

.gallery li {
  /*border: 5px dotted gold;*/
  margin: 30px 0;
}

.gallery li {
  font-size: 1.33rem;
  text-align: justify;
  padding: 10px;
  line-height: 1.5;
  margin-top: -5px;
}

/***********************
FOOTER
************************/
footer {
  text-align: center;
}

1 Answer

Steven Parker
Steven Parker
230,274 Points

Links (a) are inline elements by default, but you can make them be block elements and then apply text centering.

.gallery a {
  display: block;
  text-align: center;
}