Problem with Grid in css

Asked

Viewed 60 times

1

Well I’m having problem with the grid in css. Whenever I finish a '' it creates a bigger space. Someone knows how to solve this and leave him uniform?

Follows the code:

.column {
  background: #eee;
  border: 1px solid #ccc;
  border-radius: 4px;
  color: #777;
  padding: 5px;
  min-height: 30px;
  text-align: center;
}
.column .column {
  color: #eee;
  background: #333;
  border-color: #000;
}
.row {
  margin: 10px;
}
.row,
.column {
  box-sizing: border-box;
}
.row:before,
.row:after {
  content: " ";
  display: table;
}
.row:after {
  clear: both;
}
.column {
  float: left;
}
.column + .column {
  margin-left: 1.6%;
}
.column-1 {
  width: 6.86666666667%;
}
.column-2 {
  width: 15.3333333333%;
}
.column-3 {
  width: 23.8%;
}
.column-4 {
  width: 32.2666666667%;
}
.column-5 {
  width: 40.7333333333%;
}
.column-6 {
  width: 49.2%;
}
.column-7 {
  width: 57.6666666667%;
}
.column-8 {
  width: 66.1333333333%;
}
.column-9 {
  width: 74.6%;
}
.column-10 {
  width: 83.0666666667%;
}
.column-11 {
  width: 91.5333333333%;
}
.column-12 {
  width: 100%;
  margin-left: 0 !important;
}
/* Mobile */

@media only screen and (max-width: 900px) {
  .column-1,
  .column-2,
  .column-3,
  .column-4,
  .column-5,
  .column-6,
  .column-7,
  .column-8,
  .column-9,
  .column-10,
  .column-11,
  .column-12 {
    width: auto;
    float: none;
  }
  .column + .column {
    margin-left: 0;
  }
  .row {
    margin-bottom: 10px;
  }
  .column {
    margin-bottom: 10px;
  }
  .row:last-child .column:last-child {
    margin-bottom: 0;
  }
}
<div class="row">
  <div class="column column-4">column-4</div>
  <div class="column column-4">column-4</div>
  <div class="column column-4">Fim do row, o espaçamento fica maior</div>
</div>
<div class="row">
  <div class="column column-2">column-2</div>
  <div class="column column-4">column-4</div>
  <div class="column column-4">column-4</div>
  <div class="column column-2">Fim do row, o espaçamento fica maior</div>
</div>
<div class="row">
  <div class="column column-5">column-5</div>
  <div class="column column-7">column-7</div>
</div>
<div class="row">
  <div class="column column-6">
    <div class="row">
      <div class="column column-6">column-6</div>
      <div class="column column-6">column-6</div>
    </div>
    <div class="row">
      <div class="column column-3">column-3</div>
      <div class="column column-3">column-3</div>
      <div class="column column-3">column-3</div>
      <div class="column column-3">column-3</div>
    </div>
    <div class="row">
      <div class="column column-4">column-4</div>
      <div class="column column-4">column-4</div>
      <div class="column column-4">column-4</div>
    </div>
  </div>
  <div class="column column-6">
    <div class="row">
      <div class="column column-7">column-7</div>
      <div class="column column-3">column-3</div>
      <div class="column column-2">column-2</div>
    </div>
    <div class="row">
      <div class="column column-2">column-2</div>
      <div class="column column-2">column-2</div>
      <div class="column column-4">column-4</div>
      <div class="column column-2">column-2</div>
      <div class="column column-2">column-2</div>
    </div>
    <div class="row">
      <div class="column column-9">column-9</div>
      <div class="column column-3">column-3</div>
    </div>
  </div>
</div>
<div class="row">
  <div class="column column-8">column-8</div>
  <div class="column column-4">column-4</div>
</div>
<div class="row">
  <div class="column column-1">column-1</div>
  <div class="column column-3">column-3</div>
  <div class="column column-4">column-4</div>
  <div class="column column-3">column-3</div>
  <div class="column column-1">column-1</div>
</div>
<div class="row">
  <div class="column column-3">column-3</div>
  <div class="column column-3">column-3</div>
  <div class="column column-3">column-3</div>
  <div class="column column-3">column-3</div>
</div>
<div class="row">
  <div class="column column-12">column-12</div>
</div>

  • That space is the margin: 10px; of your .row.

  • I meant from the .column

1 answer

2


Just add

.row > .column:last-child {
  margin-bottom: 0;
}

The last column of each . Row will not have margin-bottom and your problem is solved.

Just adjust this rule to the screen size you need.

.column {
  background: #eee;
  border: 1px solid #ccc;
  border-radius: 4px;
  color: #777;
  padding: 5px;
  min-height: 30px;
  text-align: center;
}
.column .column {
  color: #eee;
  background: #333;
  border-color: #000;
}
.row {
  margin: 10px;
}

.row,
.column {
  box-sizing: border-box;
}
.row:before,
.row:after {
  content: " ";
  display: table;
}
.row:after {
  clear: both;
}
.column {
  float: left;
}
.row > .column:last-child {
  margin-bottom: 0;
}
.column + .column {
  margin-left: 1.6%;
}
.column-1 {
  width: 6.86666666667%;
}
.column-2 {
  width: 15.3333333333%;
}
.column-3 {
  width: 23.8%;
}
.column-4 {
  width: 32.2666666667%;
}
.column-5 {
  width: 40.7333333333%;
}
.column-6 {
  width: 49.2%;
}
.column-7 {
  width: 57.6666666667%;
}
.column-8 {
  width: 66.1333333333%;
}
.column-9 {
  width: 74.6%;
}
.column-10 {
  width: 83.0666666667%;
}
.column-11 {
  width: 91.5333333333%;
}
.column-12 {
  width: 100%;
  margin-left: 0 !important;
}
/* Mobile */

@media only screen and (max-width: 900px) {
  .column-1,
  .column-2,
  .column-3,
  .column-4,
  .column-5,
  .column-6,
  .column-7,
  .column-8,
  .column-9,
  .column-10,
  .column-11,
  .column-12 {
    width: auto;
    float: none;
  }
  .column + .column {
    margin-left: 0;
  }
  .row {
    margin-bottom: 10px;
  }
  .column {
    margin-bottom: 10px;
  }
  .row:last-child .column:last-child {
    margin-bottom: 0;
  }
}
<div class="row">
  <div class="column column-4">column-4</div>
  <div class="column column-4">column-4</div>
  <div class="column column-4">Fim do row, o espaçamento fica maior</div>
</div>
<div class="row">
  <div class="column column-2">column-2</div>
  <div class="column column-4">column-4</div>
  <div class="column column-4">column-4</div>
  <div class="column column-2">Fim do row, o espaçamento fica maior</div>
</div>
<div class="row">
  <div class="column column-5">column-5</div>
  <div class="column column-7">column-7</div>
</div>
<div class="row">
  <div class="column column-6">
    <div class="row">
      <div class="column column-6">column-6</div>
      <div class="column column-6">column-6</div>
    </div>
    <div class="row">
      <div class="column column-3">column-3</div>
      <div class="column column-3">column-3</div>
      <div class="column column-3">column-3</div>
      <div class="column column-3">column-3</div>
    </div>
    <div class="row">
      <div class="column column-4">column-4</div>
      <div class="column column-4">column-4</div>
      <div class="column column-4">column-4</div>
    </div>
  </div>
  <div class="column column-6">
    <div class="row">
      <div class="column column-7">column-7</div>
      <div class="column column-3">column-3</div>
      <div class="column column-2">column-2</div>
    </div>
    <div class="row">
      <div class="column column-2">column-2</div>
      <div class="column column-2">column-2</div>
      <div class="column column-4">column-4</div>
      <div class="column column-2">column-2</div>
      <div class="column column-2">column-2</div>
    </div>
    <div class="row">
      <div class="column column-9">column-9</div>
      <div class="column column-3">column-3</div>
    </div>
  </div>
</div>
<div class="row">
  <div class="column column-8">column-8</div>
  <div class="column column-4">column-4</div>
</div>
<div class="row">
  <div class="column column-1">column-1</div>
  <div class="column column-3">column-3</div>
  <div class="column column-4">column-4</div>
  <div class="column column-3">column-3</div>
  <div class="column column-1">column-1</div>
</div>
<div class="row">
  <div class="column column-3">column-3</div>
  <div class="column column-3">column-3</div>
  <div class="column column-3">column-3</div>
  <div class="column column-3">column-3</div>
</div>
<div class="row">
  <div class="column column-12">column-12</div>
</div>

  • Thank you so much for your help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.