0

Due to the justify-content: space-around rule, when 4th block jumps down, it becomes in the middle

can I somehow still use the space-around rule, but make the last block do not jump to the center, but to the left, like in the screenshot ?? P.S. I still need justify-content: space-around because of it responsive margins

Here is the code https://jsfiddle.net/s4fbtkyg/

<html>
<body>

<style>
  .block{
  background-color: grey;
  flex-basis: 100px;
  margin-bottom: 5px;
}

.container{
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}
</style>

<div class="container">
  <div class="block">1</div>
  <div class="block">2</div>
  <div class="block">3</div>
  <div class="block">4</div>
 </div>
</body>
</html>

screenshot

Jack Surma
  • 23
  • 4

1 Answers1

0

you might want to consider CSS grid for this task using:

grid-template-columns: repeat(auto-fit, 100px); //100px being the width of your choosing

Here is the code:

HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
<div class="container">
  <div class="block">1</div>
  <div class="block">2</div>
  <div class="block">3</div>
  <div class="block">4</div>
 </div>
</body>
</html>

CSS

.block{
  background-color: grey;
}

.container{
  display: grid;
  grid-gap: 5px;
  grid-template-columns: repeat(auto-fit, 100px);
  justify-content: space-around; //you can still use justify-content: space-around

}

fiddle: fiddle link

Dostrelith
  • 922
  • 5
  • 13