当前位置: 首页 > news >正文

CSS经典布局之圣杯布局和双飞翼布局

目标:

中间自适应,两边定宽,并且三栏布局在一行展示。

圣杯布局

实现方法:

通过float搭建布局+margin使三列布局到一行上+relative相对定位调整位置;

给外部容器添加padding,通过相对定位调整左右两列的位置。

<div id="header">#header</div><div id="container"><div id="center" class="column">#center</div><div id="left" class="column">#left</div><div id="right" class="column">#right</div></div>
<div id="footer">#footer</div>
#header, #footer {background: rgba(29, 27, 27, 0.726);text-align: center;height: 60px;line-height: 60px;clear: both;
}
#container{padding: 0 200px;overflow: hidden;/*形成BFC撑开文档*/
}
.column{height: 200px;float: left;position: relative;
}
#center{width: 100%;background-color: tomato;
}
#left{width: 200px;margin-left: -100%; /* 把left移动到和center同一行并且左边对齐 */left: -200px; /* 再向左移动到main的padding区域,就不会挡住center了 */background-color: aqua;
}
#right{width: 200px;margin-left: -200px; /* 把right移动到和center同一行并且右边对齐 */right: -200px; /* 向右移动到右边的padding区域*/background-color: wheat;
}

圣杯布局效果

双飞翼布局

实现方法:

通过float+margin,不使用相对定位;

在中间层外面套一层div,加上margin将 center内容 挤到中间

<div id="header">#header</div><div id="container"><div id="center" class="column"><div id="center-content">#center</div></div><div id="left" class="column">#left</div><div id="right" class="column">#right</div>
</div><div id="footer">#footer</div>
#header, #footer {background: rgba(29, 27, 27, 0.726);text-align: center;height: 60px;line-height: 60px;clear: both;
}
.column{height: 200px;float: left;
}
#center{width: 100%;background-color: tomato;
}
#center-content{margin: 0 200px;
}
#left{width: 200px;margin-left: -100%; /* 作用和圣杯一样 */background-color: aqua;}
#right {width: 200px;margin-left: -200px; /* 作用和圣杯一样 */background-color: wheat;
}

双飞翼布局

两者本质区别

相关文章:

  • NLTK库: 数据集3-分类与标注语料(Categorized and Tagged Corpora)
  • archlinux中挂载macOS的硬盘
  • Mac修改hosts文件方法
  • 信息论14:从互信息到信息瓶颈——解锁数据压缩与特征提取的秘密
  • Jsp技术入门指南【十三】基于 JSTL SQL 标签库实现 MySQL 数据库连接与数据分页展示
  • Excel宏和VBA的详细分步指南
  • 进程间通信分类
  • org.slf4j.MDC介绍-笔记
  • 奇怪的公式
  • IntelliJ IDEA给Controller、Service、Mapper不同文件设置不同的文件头注释模板、Velocity模板引擎
  • 【认知思维】光环效应:第一印象的持久力量
  • 中国版 Cursor---腾讯云 CodeBuddy | 从安装VSCode到数独小游戏问世
  • IDEA查看类结构视图窗口,接口的所有的实现类图
  • TensorFlow 常见使用场景及开源项目实例
  • Spring WebFlux 与 WebClient 使用指南
  • PHP-FPM 调优配置建议
  • 开源自定义Python库并上传到PyPi
  • 利用 Python 进行量化的主要步骤
  • .Net HttpClient 使用Json数据
  • 原生小程序+springboot+vue医院医患纠纷管理系统的设计与开发(程序+论文+讲解+安装+售后)
  • 俄副外长:俄美两国将举行双边谈判
  • 国务院关税税则委员会关于调整对原产于美国的进口商品加征关税措施的公告
  • 中美是否计划讨论美方以芬太尼为由对华征收的特别关税?外交部回应
  • 王毅会见巴西外长维埃拉、总统首席特别顾问阿莫林
  • 科普|“小”耳洞也会引发“大”疙瘩,如何治疗和预防?
  • 人民日报:浙江着力提升民营企业核心竞争力