-5

I want to create even spacing between my ul list: New Upload and Share. See example below.

I use justify-items: space-between among other variations to try to evenly distribute my ul items but with no obvious effect. I do not understand as the container appears to have space to redistribute the grids along the inline axis. So why isn't it working?

Update: I see that the actual problem is that the ul isn't spanning to the right end of the column, therefore, it is confined to the second column only.

* {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

div,
li {
  border: 1px solid rgb(142, 28, 47);
}

.header {
  display: grid;
  grid-template-columns: 5fr 1fr 1fr;
}

ul {
  grid-template-columns: 2 / 4;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  justify-content: space-between;
}
<div class="header">
  <div class="Search">Search</div>
  <div class="Alert">Alert</div>
  <div class="User Info">User Info</div>
  <div class="Intro">Hi There</div>
  <ul>
    <li>New</li>
    <li>Upload</li>
    <li>Share</li>
  </ul>
</div>

5
  • 3
    Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. Commented Aug 5 at 20:18
  • 1
    justify-items: center ? Commented Aug 5 at 23:38
  • 1
    space-between isn't a value for justify-items. See the documentation - justify-items Commented Aug 6 at 6:38
  • 2
    Perhaps you mean to use justify-content: space-between. But the same documentation (see the comment above) says that it is applicable to a flex container you're not using. Commented Aug 6 at 7:37
  • I changed it to justify-content. However, the problem remains that the ul isn't spanning the rest of the grid track or columns to the right end. Commented Aug 7 at 14:49

1 Answer 1

0
<style>
  * {
    list-style-type: none;
    margin: 0;
    padding: 0;
  }

  div, li {
    border: 1px solid rgb(142, 28, 47);
  }

  .header {
    display: grid;
    grid-template-columns: 5fr 1fr 1fr;
  }

  ul {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
  }
</style>

<div class="header">
  <div class="Search">Search</div>
  <div class="Alert">Alert</div>
  <div class="User Info">User Info</div>
  <div class="Intro">Hi There</div>
  <ul>
    <li>New</li>
    <li>Upload</li>
    <li>Share</li>
  </ul>
</div>
justify-items controls how items are aligned inside each individual grid cell, not how the items themselves are spaced in the container.
space-between is not a valid value for justify-items.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.