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

相关推荐
棉花糖超人1 小时前
【从0-1的CSS】第1篇:CSS简介,选择器已经常用样式
前端·css
potender2 小时前
前端基础学习html+css+js
前端·css·学习·html·js
Hilaku2 小时前
你以为的 Tailwind 并不高效,看看这些使用误区
前端·css·前端框架
Hilaku3 小时前
为什么越来越多 Vue 项目用起了 UnoCSS?
前端·css·html
中微子3 小时前
☀️这些CSS里的选择器你知道多少❓
css
Larcher3 小时前
css真难,那就从基础开始吧
前端·css
Linsk3 小时前
深入解析 Sass 的 `~` 路径问题:为什么你的导入会失败?
css·scss·前端工程化
站在风口的猪11084 小时前
《前端面试题:CSS3新特性》
前端·css·html·css3·html5
ayuday6 小时前
stylus - 新生代CSS预处理框架
css·stylus
Dream耀6 小时前
CSS选择器完全手册:精准控制网页样式的艺术
前端·css·html