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 中间自适应

相关推荐
inksci9 小时前
用飞帆做了个小网页
前端·javascript·css·html
星云_byto17 小时前
CSS面试题
前端·css
科研邪修法1 天前
PDF新增页面文字与文本批注怎么区分?以双版本培训讲义为例
前端·css·pdf
狮子座的男孩2 天前
html+css基础:31、响应式布局(媒体类型,媒体特性,运算符,常用阈值)
前端·css·经验分享·html·响应式布局·媒体类型/特性·常用阈值
狮子座的男孩2 天前
html+css基础:32、BFC(父子元素防止 margin 塌陷,父子元素清除浮动,兄弟元素两栏布局)
前端·css·经验分享·html·bfc·margin塌陷·清除浮动
吴长建先生2 天前
Flutter IM 即时聊天应用开发:从 0 到 1 实
css
htzyl2063 天前
前端样式-弹窗淡入淡出,为什么你的 `transition` 一直不生效
前端·css·html
Brookty3 天前
CSS基础知识(二):盒模型、内外边距、外边距折叠与父子元素的布局关系
前端·css
Mh4 天前
我是如何设计品牌站组件库的?
前端·css·设计模式
Brookty4 天前
CSS基础知识(一):选择器、优先级、层叠与继承、边框属性及盒模型
前端·css