0

I am working with flexbox to make the grid of a webpage and instead of adding breakpoints I think would be best to select the elements that are alone in a row. For example, using flex-wrap: wrap, select the elements that eventually become alone in a row.

Example of what I was expecting but doesn't exists:

.row {
  display: flex;
  align-items: center;
  justify-items: flex-start;
  flex-wrap: wrap;
}

.row > .column {
   margin: 15px;
   width: auto;

   &:alone-in-row { // HERE 
     width: 100%;
     text-align: center;
   }
}

1 Answers1

0

You could use the :only-child pseudoselector:

.row {
  display: flex;
  align-items: center;
  justify-items: flex-start;
  flex-wrap: wrap;
}

.row .column {
  margin: 15px;
  width: auto;
}

.row .column:only-child {
  width: 100%;
  text-align: center;
}
<table>
  <tr class="row">
    <td class="column">1</td>
    <td class="column">2</td>
  </tr>
  <tr class="row">
    <td class="column">1</td>
  </tr>
</table>
Michael Rodriguez
  • 2,142
  • 1
  • 9
  • 15