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

弹性布局

弹性布局已经成为移动端最流行的布局方式之一了,还不了解的同学赶快去了解一下吧!本节我们就以弹性布局的方式实现单列布局。

<!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: center;
    }

    .center {
      /* 相当于flex版的width: 90% */
      flex-basis: ;

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

运行结果:

如果对弹性盒子不太了解的直接记住这几个要点即可:

下一小节我们来讲一下绝对定位 + 平移来实现单列布局。


联系我
置顶