0

I'm trying to center an absolutely positioned navigation, but there is extra space to the right on large screen sizes.

I looked at some other similar StackOverflow questions and tried to add the following to the ul:

left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
*, *:before, *:after { box-sizing: border-box; margin: 0; padding: 0;
border: none;}

.section-border {
  background-color: #f8f7f3;
  min-height: 100vh;
  border: 30px solid #ffffff;
}

.header {
  max-width: 960px;
  height: 100%;
  margin-left: 1rem;
  margin-right: 1rem;
  position: relative;
}

.menu {
  display: flex;
  position: absolute;
  top: -0.83rem;
  left: 0;
  right: 0;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
  max-width: 960px;
  line-height: 1.5em;
}

li {
  display: inline-block;
  flex-grow: 1;
  font-size: 14px;
}

@media only screen and (min-width: 601px) {
  .home-link {
    order: -1;
    flex-grow: 0;
  }

  li {
    text-align: right;
  }
}

<div class="section-border">
  <header class="header">
    <nav role="navigation">
      <ul class="menu">
        <li class="home-link" aria-hidden="true"><a href="#"><img src="https://www.nicolefenton.com/_/images/dec/circle-menu.svg" height="12" width="12" alt=""></a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Writing</a></li>
        <li><a href="#">Speaking</a></li>
        <li><a href="#">Projects</a></li>
      </ul>
    </nav>
  </header>
</div>

I want the ul to be centered irrespective of the viewport size.

cklein23
  • 83
  • 6
  • 2
    Possible duplicate of [How to center absolutely positioned element in div?](https://stackoverflow.com/questions/1776915/how-to-center-absolutely-positioned-element-in-div) (I suggest referencing [**this answer**](https://stackoverflow.com/a/23384995/2026606), using `transform: translate(-50%,-50%)`, as opposed to the accepted answer) – Tyler Roper Jun 24 '19 at 19:17
  • It's way better to put HTML as well. – EshgheCode Jun 24 '19 at 19:17
  • I just added the HTML. Tyler, thanks for the response. I just tried using that on the menu class and unfortunately, the problem persists. – cklein23 Jun 24 '19 at 19:25

0 Answers0