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

Taylor Bryce
Taylor Bryce
835 Points

How do i centre gallery list items ?

Hi, I have finished the How To Make A Website and have am now looking to edit the CSS.

Since the course ended, I have updated the html to only have four images while keeping the existing css intact.

I have noticed though that gallery list items are off entered to the left hand side. I take it this is because of the li {float:left;} ?

How do i make these 4 list items sit centre in the screen while keeping it intact to have two items per row?

Below is my css + html:

HTML:

        <ul id=gallery>
          <li>
            <a href="img/tour.jpg">
              <img src="img/tour.jpg" alt="">
              <p>Up Coming Show</p>
            </a>  
          </li>
          <li>
            <a href="img/perform.jpg">
              <img src="img/perform.jpg" alt="">
              <p>Music</p>
            </a>  
          </li>
          <li>
            <a href="img/vidshoot.jpg">
              <img src="img/vidshoot.jpg" alt="">
              <p>Videos</p>
            </a>  
          </li>
          <li>
            <a href="img/merch.jpg">
              <img src="img/merch.jpg" alt="">
              <p>Merch</p>
            </a>  
          </li>
        </ul>
      </section>```


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

#gallery li {
  float: left;
  width: 45%;
  margin: 1%;
  padding: 1%;
  background-color: #d9d9d9;
  color: #bdc3c7;
}

#gallery li a p {
  margin: 0;
  padding: 3%;
  font-size: 0.75em;
  color: #000;
}



Thanks in advance!

1 Answer

Adrian Sawicki
Adrian Sawicki
5,962 Points

Can you paste here your whole html and css ?