1

Struggling with CSS grid and could do with a bit of help.

I've got a <section> item with 4 items, these should be separated 2 on the left, 2 on the right, centered vertically.

However, when my Vue component state variable changes, the items are filtered down to just the two on the right.

How do I keep the correct format of the grid so the two columns stay on the right when there are less items in the grid?

basic example of the grid

So far I have this for the main outer div...

display: grid;
grid-template-columns: 1fr auto;
grid-column-gap: 1.25em;
align-items: center;

and this for my two inner right divs

display: grid;
justify-content: right;
align-content: center;
1

2 Answers 2

1

For your inner div:

Instead of using justify-content: right;, which isn't a thing, use: justify-content: flex-end;

Justify-content: flex-end; places everything at the end, depending what the flex-direction is. The same counts for justify-content: flex-start; of course, which places everything at the beginning.

Sign up to request clarification or add additional context in comments.

Comments

0

Maybe this way with extra div to hold right items:

.container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, auto));
  grid-column-gap: 1.25em;
  align-items: center;
  background-color: grey;
  padding: 1em;
  margin-bottom: 1em;
}
.right {
  justify-self: end;
  display: flex;
  align-items: center;
}
.item {
  background-color: orange;
  margin: 0 1em;
  padding: 2em;
}
<div class="container">
  <div class="item"></div>
  <div class="item"></div>
  <div class="right">
    <div class="item"></div>
    <div class="item"></div>
  </div>
</div>
<div class="container">
  <div class="right">
    <div class="item"></div>
    <div class="item"></div>
  </div>
</div>

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.