How do I make 2 or more horizontal divs stack into a vertical div when the user shrinks the browser window?

后端 未结 2 1184
时光取名叫无心
时光取名叫无心 2021-01-24 19:38

I have 2 divs on same row, each with a width of 50% and a float: left. I would like them to stack one on top of the other if the user is viewing the page from a smart-phone. Rig

2条回答
  •  礼貌的吻别
    2021-01-24 19:55

    Use media queries:

    @media screen and (min-width: 321px) {
      #wrapper {width: 100%;}
      .content {
        width: 50%;
        float: left;
      }
    }
    @media screen and (max-width: 320px) {
      #wrapper {width: 100%;}
      .content {
        width: 100%;
        float: none;
      }
    }
    

提交回复
热议问题