RJorns
RJorns

Reputation: 281

Centering and spacing icons in footer

How can I get these icons to be in a row and have space-around? having trouble understanding why they are not automatically in a row... Would like for them to be in a row, with space around and centered. Would be great if they could also stack when getting smaller than 768px. What am I missing here?

Codepen Footer

<footer>
  <div class="credit">
    <p>2018 Roger Jorns</p>
  </div>
  <div class="footer-logo">
    <img class="footer-pic" src="/Users/rogerjorns/Desktop/Portfolio/food site/assets/images/LogoMakr_1KiQWa.png" alt="">
  </div>
  <div class="social">
    <ul class="icons">
      <li><i class="fab fa-facebook-f"></i></li>
      <li><i class="fab fa-twitter"></i></li>
      <li><i class="fab fa-instagram"></i></li>
      <li><i class="fab fa-yelp"></i></li>
    </ul>
  </div>
</footer>

footer {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-auto-rows: 1fr;
  width: 100%;
  background-color: gray;
}

li {
  list-style: none;
}

.credit {
  grid-column: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.footer-logo {
  grid-column: 2;
  width: 40%;
  margin: 0 auto;
}

.social {
  grid-column: 3;
  display: flex;
  justify-content: center;
  align-items: center;
}

Upvotes: 0

Views: 947

Answers (2)

Stony
Stony

Reputation: 150

The flex property has to target the direct parent container element, which is not .social but .icons.

https://codepen.io/anon/pen/PBVdNJ

Upvotes: 1

onyx
onyx

Reputation: 1618

They don't appear in row because list-items or <li> elements have default display property as: display: list-item. Use flexbox to display them as row and have space around.

footer {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-auto-rows: 1fr;
  width: 100%;
  background-color: gray;
}

li {
  list-style: none;
}

.credit {
  grid-column: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.footer-logo {
  grid-column: 2;
  width: 40%;
  margin: 0 auto;
}

.social {
  grid-column: 3;
  display: flex;
  justify-content: center;
  align-items: center;
}

ul {
  display: flex;
  justify-content: space-around;
  width: 100%;
}

@media only screen and (max-width: 600px) {
    ul {
      display: initial;
    }
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/brands.css" integrity="sha384-nT8r1Kzllf71iZl81CdFzObMsaLOhqBU1JD2+XoAALbdtWaXDOlWOZTR4v1ktjPE" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/fontawesome.css" integrity="sha384-HbmWTHay9psM8qyzEKPc8odH4DsOuzdejtnr+OFtDmOcIVnhgReQ4GZBH7uwcjf6" crossorigin="anonymous">

<footer>
  <div class="credit">
    <p>2018 Roger Jorns</p>
  </div>
  <div class="footer-logo">
    <img class="footer-pic" src="/Users/rogerjorns/Desktop/Portfolio/food site/assets/images/LogoMakr_1KiQWa.png" alt="">
  </div>
  <div class="social">
    <ul class="icons">
      <li><i class="fab fa-facebook-f"></i></li>
      <li><i class="fab fa-twitter"></i></li>
      <li><i class="fab fa-instagram"></i></li>
      <li><i class="fab fa-yelp"></i></li>
    </ul>
  </div>
</footer>

If you want the icons to stack when the device is less than 786px, use media-queries to disable flex-box.

Upvotes: 1

Related Questions