How to get columns to break into rows with flexbox?

后端 未结 2 1563
我寻月下人不归
我寻月下人不归 2021-01-25 00:18

I have this form with four input elements in a row (in desktop view).

Can anybody tell me how to get those four input elements to break into rows when the screen width g

2条回答
  •  感动是毒
    2021-01-25 00:52

    By default, flex items line up in a row. An initial value on a flex container is flex-direction: row.

    Switching to flex-direction: column is one good method for stacking items vertically. This method is already covered in another answer.

    Another method would be to enable flex-wrap and give each input width: 100%.

    This would allow only one input per row, forcing subsequent inputs to wrap.

    form { display: flex;}
    
    input { width: 25%; }
    
    @media ( max-width: 680px ) {
      form { flex-wrap: wrap; }
      input { width: 100%; }
    }

    jsFiddle

提交回复
热议问题