您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

弹性布局

弹性布局已经成为移动端最流行的布局方式之一了,还不了解的同学赶快去了解一下吧!

本小节就会带领大家一起用最流行的方式来实现双列布局。

<!DOCTYPE html>
<html lang="en">
<head>
  < charset="UTF-8">
  < name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    /* 清除认样式 */
    * { padding: ; margin: ; }

    /* 令html和body全屏, 并有灰色背景 */
    html, body { height: ; background: gray; }

    /* 找到直接父元素 */
    body {
      /* 为弹性盒子 */
      display: flex;

      /* 令其子元素在水平方向上均匀分布 */
      justify-content: space-evenly;
    }

    div {
      /* 这里类似于width: 48% */
      flex-basis: ;

      /* 给个高度 */
      height: ;

      /* 白色背景 */
      background: white;
    }
  </style>
</head>
<body>
  <div></div>
  <div></div>
</body>
</html>

运行结果:

子元素一般会用 flex-basis 来表示在父元素所占的长度。

因为 flex 盒子不仅有横着的,还会有竖着的。假如竖着的再叫宽就不太合适了,所以取了 flex-basis 这么名字作为新的来表示长度( 横着的时候代表宽,竖着的时候代表高 )。


联系我
置顶