如何使用 CSS 创建 3 列布局网格?


若要使用 CSS 创建 3 列布局网格,代码如下 −

示例

 实时演示

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
   body {
      padding: 1%;
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   }
   * {
      box-sizing: border-box;
   }
   .left, .right, .center {
      float: left;
      width: 33%;
      color: white;
      padding: 10px;
      height: 500px;
      text-align: center;
   }
   .left {
      background-color: tomato;
   }
   .right {
      background-color: teal;
   }
   .center {
      background-color: rgb(166, 71, 255);
   }
   .container:after {
      clear: both;
   }
</style>
</head>
<body>
<h1 style="text-align: center;">Three Column grid example</h1>
<div class="container">
<div class="left">
<h1>Some text on the left</h1>
</div>
<div class="center">
<h1>Some text in center</h1>
</div>
<div class="right">
<h1>Some text on the right</h1>
</div>
</div>
</body>
</html>

输出

以上代码将生成以下输出 −

更新于:2020 年 5 月 12 日

3K+ 次浏览

开启你的 职业生涯

完成课程获得认证

开始学习
广告
© . All rights reserved.