0

I'm trying to place seven columns of the same size in one row:

.seven-cols .col-hard-1 {
  width: 14.28%;
  *width: 14.28%;
  float: left;
}

However, float:left screws up the all the next blocks on the page. Is there a way to make this grid without using float?

Codepen

1 Answer 1

2

Use display: flex; on the container and flex-grow: 1; and flex-basis: 0; on the items to make them all take up the same amount of available space.

.seven-cols {
  display: flex;
}
.seven-cols .col-hard-1 {
  flex-grow: 1;
  flex-basis: 0;
}
<div class="seven-cols">
  <div class="col-hard-1">
    one
  </div>

  <div class="col-hard-1">
    two
  </div>

  <div class="col-hard-1">
    three
  </div>

  <div class="col-hard-1">
    four
  </div>

  <div class="col-hard-1">
    five
  </div>
  <div class="col-hard-1">
    six
  </div>
  <div class="col-hard-1">
    seven
  </div>
</div>

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

1 Comment

That's a great solution. I totally forgot about flex. Thanks!

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.