CSS双飞翼布局

双飞翼布局是一种经典的CSS布局模式,主要用于实现左右两列固定宽度,中间列自适应的布局。

比如:写一个左中右布局占满全屏,其中左、右两块固定宽 200px,中间自适应,要求先加载中间块。

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>双飞翼布局</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      body {
        width: 100vw;
        height: 100vh;
        color: #fff;
      }
        /* 内容区域 */
        .container > div {
          float: left;
        }

        /* 左侧栏 */
        .left {
          width: 200px;
          height: 100vh;
          margin-left: -100%;
          background-color: red;
        }

        /* 右侧栏 */
        .right {
          width: 200px;
          height: 100vh;
          margin-left: -200px;
          background-color: blue;
        }

        /* 中间栏 */
        .middle {
          width: 100%;
          height: 100vh;
          background-color: pink;
        }
        .main {
          padding: 0 200px;
        }
    </style>
</head>
<body>
  <!-- 双飞翼布局 -->
    <div class="container">
        <div class="middle">
          <div class="main">中间自适应内容</div>
        </div>
        <div class="left">左侧固定宽度</div>
        <div class="right">右侧固定宽度</div>
    </div>
</body>
</html>

左右 200px 中间自适应

相关推荐
吕永强29 分钟前
CSS相关属性和显示模式
前端·css·css3
赵锦川35 分钟前
css三角形:css画箭头向下的三角形
前端·css
小白求学13 小时前
CSS计数器
前端·css
吕永强8 小时前
CSS概述
前端·css·css3
yqcoder11 小时前
css 选择除第一个子元素之外的所有子元素
前端·css
blaizeer11 小时前
深入浅出 CSS 定位:全面解析与实战指南
前端·css
wave_sky11 小时前
HTML&&CSS练习
前端·css·html
过期的H2O212 小时前
【H2O2|全栈】关于CSS(10)CSS3扩充了哪些新鲜的东西?(三)
前端·css·css3
小小李程序员14 小时前
CSS3渐变
前端·css·css3
莘薪18 小时前
HTML的修饰(CSS) -- 第三课
前端·css·html·框架