material-design-lite icon indicating copy to clipboard operation
material-design-lite copied to clipboard

How to break a row in the grid?

Open Taakn opened this issue 10 years ago • 6 comments

Hello,

I can't find it in the docs, but how do you break a row after a certain cell in the grid ? For example, how do I get the following layout ?

X X X X X X X X X

On a smaller screen, it would look like:

X X X X X X X X X

Thanks so much

Taakn avatar Jul 06 '16 22:07 Taakn

There may be a better way to do this, but I would add a spacer that's hidden on smaller screens.

http://codepen.io/westy92/pen/qNXmWR

<div class="mdl-grid">
  <div class="mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet mdl-cell--4-col-phone">X X X</div>
  <div class="mdl-cell mdl-cell--6-col mdl-cell--hide-tablet mdl-cell--hide-phone"></div>
  <div class="mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet mdl-cell--4-col-phone">X X X</div>
  <div class="mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet mdl-cell--4-col-phone">X X X</div>
</div>

westy92 avatar Jul 07 '16 05:07 westy92

@westy92 Thanks a lot that works! For me this feature is particularly important for forms where I have a lot of inputs and I can't have them all one after the other.

Even though this works perfectly, I feel there should be a "native", more elegant way of handling this so I am leaving this issue open for now.

Taakn avatar Jul 07 '16 07:07 Taakn

Unfortunately the solution didn't end up working well (because of all the different possible layout combinations) so the only way for now is really to have an mdl-grid per row.

Taakn avatar Jul 07 '16 10:07 Taakn

@westy92's solution is the current recommended solution. If you need something more complex then you're probably better of building your own setup for handling the form.

Garbee avatar Jul 07 '16 11:07 Garbee

Thanks again for your answers. I am using Material UI and just needed a grid so in the end I'll be using http://flexboxgrid.com/ which works well for me for a couple of additional reasons:

The column / rows setup is more intuitive. Overall it has more options.

It's a lightweight css-only solution, so works well with dynamically-added elements (no need to use componentHandler.upgradeElement)

It handles well 0px margins for the leftmost and rightmost elements.

Taakn avatar Jul 07 '16 14:07 Taakn

You can add <Grid sm={12}/> after the first three elements.

pacohernandezg avatar Feb 13 '19 22:02 pacohernandezg