将桌面布局转换为单列移动布局 [英] Converting desktop layout to single-column mobile layout

查看:38
本文介绍了将桌面布局转换为单列移动布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个完整的网站,但删除了所有填充物并离开了3列的div.我的目标是在调整图像大小时使这3列垂直堆叠.

I had an entire site created, but removed all the filler and left the 3-column divs. My goal is to have these 3 columns stack vertically as the image is resized.

包含了其他CSS,因为它与网站的其余部分一起使用,所以我全部包含了.

The additional css is included as it was used with the rest of the site, so I included it all.

我尝试查找某些媒体查询,并尝试将自己的头缠在flexbox上.任何帮助将不胜感激.

I tried looking up certain media queries and tried wrapping my head around flexbox. Any help would be appreciated.

  * {
  border: 1px solid red;
  /*For layout purposes only*/
}

* {
  max-width: 980px;
  font-family: 'Lato', sans-serif;
  margin-left: auto;
  margin-right: auto;
  padding-bottom: 0px;
}

* {
  box-sizing: border-box;
}

.container {
  display: flex;
  flex-wrap: wrap;
  overflow: hidden;
}

.row {
  width: 100%;
  display: flex;
}

.img {
  display: block;
  margin: auto;
}

.col-1 {
  width: 8.33%;
}

.col-2 {
  width: 16.66%;
}

.col-3 {
  width: 25%;
}

.col-4 {
  width: 33.33%;
}

.col-5 {
  width: 41.66%;
}

.col-6 {
  width: 50%;
}

.col-7 {

<header class="container">
  <div class="row">
    <div class="col-4">
      <img class="img" src="http://placehold.it/300x300">
    </div>
    <div class="col-4">
      <img class="img" src="http://placehold.it/300x300">
    </div>
    <div class="col-4">
      <img class="img" src="http://placehold.it/300x300">
    </div>
  </div>
</header>

推荐答案

flex容器的初始设置为

An initial setting of a flex container is flex-direction: row. That means that the children of the container ("flex items") will align horizontally, just like in your code.

要垂直堆叠物品,请切换到 flex-direction:column .

To stack items vertically, switch to flex-direction: column.

.row {
    display: flex;
    flex-direction: column; /* NEW */
}

如果您希望弹性项目在调整尺寸时垂直堆叠,请在媒体查询中更改 flex-direction :

If you want flex items to stack vertically on resize, change the flex-direction in a media query:

@media screen and ( max-width: 500px ) { 
     .row { flex-direction: column; }
   }

这篇关于将桌面布局转换为单列移动布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆