2

Link to codepen

I am trying to align the copyright element in my ul to the right. The list is configured as display: inline-flex. Strangely, the last item appears to not be moving at all.

nav {
  text-align: center;
  font-family: Helvetica;
  opacity: 0.8;
  background: #222222;
  position: absolute;
  bottom: 0;
  width: 100%;
}

nav li {
  display: inline-flex;
  flex-wrap: wrap;
  flex-direction: row;
  font-size: 1em;
  margin-right: .625em;
}

#copyright {
  margin-left: auto;
}
<footer>
  <nav>
    <ul>
      <li><a href="index.html">Home</a></li>
      <li><a href="about.html">About</a></li>
      <li><a href="disclaimer.html">Disclaimer</a></li>
      <li><a href="safety.html">Safety</a></li>
      <li><a href="privacy-policy.html">Privacy Policy</a></li>
      <li><a href="contact.html">Contact</a></li>
      <li id="copyright">&copy; 2020 Copyright LLC</li>
    </ul>
  </nav>
</footer>

My understanding is that margin-left: auto should have pushed the last list element to the right, achieving my goal. I read somewhere that margin-left: auto does not work on inline flexbox, although I can't find that link anymore to confirm. Can anyone verify?

Community
  • 1
  • 1
  • Does this answer your question? [Center and right align flexbox elements](https://stackoverflow.com/questions/38948102/center-and-right-align-flexbox-elements) – Kay May 27 '20 at 07:06

1 Answers1

2

Display flex will affect the inside/children of the element applied to it. You would have to put a display flex on the ul, only child items to a flex gets positioned with margin auto.strong text

nav {
  text-align: center;
  font-family: Helvetica;
  opacity: 0.8;
  background: #222222;
  position: absolute;
  bottom: 0;
  width: 100%;
}

nav ul {
  display: flex;
}

nav li {
  display: inline-flex;
  flex-wrap: wrap;
  flex-direction: row;
  font-size: 1em;
  margin-right: .625em;
}

#copyright {
  margin-left: auto;
}
<footer>
  <nav>
    <ul>
      <li><a href="index.html">Home</a></li>
      <li><a href="about.html">About</a></li>
      <li><a href="disclaimer.html">Disclaimer</a></li>
      <li><a href="safety.html">Safety</a></li>
      <li><a href="privacy-policy.html">Privacy Policy</a></li>
      <li><a href="contact.html">Contact</a></li>
      <li id="copyright">&copy; 2020 Copyright LLC</li>
    </ul>
  </nav>
</footer>
Dejan.S
  • 18,571
  • 22
  • 69
  • 112
  • Thank you for reformatting my first question. Thank you for pointing out that child items to a flex can get margin-auto, not the parent items. While your solution pushed the copyright to the right of the page, ```margin-left: auto``` pushed the other ```li``` elements to the left. Presumably to give #copyright more space. I tried to correct by adding ```align-items: center``` to ```nav li``` and other similar lines, but to no avail. Any advice? Thank you. – joshjones506 May 27 '20 at 06:25
  • @joshjones506 sure I could help you. What is it that you want to do? – Dejan.S May 27 '20 at 08:19