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

弹性布局

已经成为移动端最流行的布局方式之一了,本小节我们将会使用弹性布局的方式来实现我们的居中布局。

<!DOCTYPE html>
<html>
<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;
    }

    .center {
      /* 外边距 */
      margin: auto;

      /* 白色背景 */
      background: white;

      /* 不用给宽高,但是可以给个内边距防止与盒子过于贴合 */
      padding: px;
    }
  </style>
</head>
<body>
  <div class="center">用撑开盒子</div>
</body>
</html>

运行结果:

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

下一小节我们来讲一讲表格布局,顺便为了降低大家的学习成本,为大家推荐需要重点练会的布局,其他布局作为了解即可。


联系我
置顶