How to avoid an extra space on the right while creating a navigation bar using flexbox (justify-content: space-between/around) properties

Viewed 56

enter image description hereI got stack by a simple thing... I am trying to create a simple navigation for my footer. So, I created a and placed an in it. The list contains three

  • s and each of them has an inside. I wish my list items to be placed horizontally with spaces between / around them. Thus, I decided to use flexbox in this case. The question is that when I am setting display property value of my to flex and justify-content to center, it work predictably (i.e. all the list items sticked to each other are centered horizontally), however, as soon as I set justify-content to "space-between" or "space-around" I get an extra space to the right side of my content, which makes this space three times bigger than the one on the left side of the content. I tried to search this topic in the history, but found nothing similar. Google search brought me a potential solution - to set flex:1 to each of the list items. But in this case I loose the gaps between the items which is not my intention. Below I provide a picture of the problem and my testing code snippets. One more observation is that everything works great in code snippets programs (JSFiddle or Code Pen)... Problem illustration

    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    
    .footer {
      height: 100vh;
      background: grey;
      position: relative;
    }
    .container {
      width: 90%;
      height: 30vh;
      margin: auto;
      position: absolute;
      top: 20%;
      left: 50%;
      transform: translateX(-50%);
    }
    
    .nav {
      background: white;
      height: 100%;
    }
    
    .list {
      height: 100%;
      list-style-type: none;
      text-align: center;
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around;
      align-items: center;
    }
    
    .item {
      min-width: 30%;
      background: grey;
    }
    <div class="footer">
        <div class="container">
          <nav class="nav">
            <ul class="list">
              <li class="item"><a href="">1</a></li>
              <li class="item"><a href="">2</a></li>
              <li class="item"><a href="">3</a></li>
            </ul>
          </nav>
        </div>
      </div>

  • 1 Answers

    Your code snippet is ok. In your screenshot it seems you have a lot more css going on, though.

    I can't see the complete CSS-snippet in your screenshot and I might be completely wrong: It looks like a piece of the clearfix-hack where you are missing the ::before part. Because adding an empty space only in ::after will have exactly the effect you are describing. It probably is the remains of a former float-construct, so you can just remove the ::after part.

    Related