当前位置:网站首页>基于“无依赖绝对定位”实现的圣杯三栏布局
基于“无依赖绝对定位”实现的圣杯三栏布局
2022-08-02 19:36:00 【huaqi_】
引用自笔者的《CSS 世界》阅读笔记。
前置问题:若一个绝对定位元素,没有任何 left/top/right/bottom 属性设置,并且其祖先元素全部都是非定位元素,其位置在哪里?
仍是在当前位置。
注:absolute 是非常独立的 CSS 属性值,其样式和行为表现不依赖其他任何 CSS 属性就可以完成。
作者将这种无 top/right/bottom/left 属性值的绝对定位称为无依赖绝对定位。
<style> /* huaqi_ 版本圣杯布局实现 */ #container {
/* 此处声明 relative 不影响无依赖定位 为使 .right 声明 margin-left: 100% 生效,需要确定其容器 */ position: relative; height: 200px; margin-left: 150px; margin-right: 200px; } p {
position: absolute; } .center {
width: 100%; height: 100px; background-color: rgba(255, 0, 0, 0.7); } .left {
width: 150px; height: 100px; margin-left: -150px; background-color: rgba(0, 0, 255, 0.6); } .right {
width: 200px; height: 100px; margin-left: 100%; background-color: rgba(33, 33, 33, 0.6); } </style>
<!-- 圣杯布局 -->
<div id="container" class="clearfix">
<p class="center">中间内容</p>
<p class="left">左侧内容</p>
<p class="right">右侧内容</p>
</div>
边栏推荐
- Dynamically generate different types of orders, how do I deposit to mongo database?
- golang面试题
- Soft Exam ----- UML Design and Analysis (Part 2)
- ShardingSphere-proxy +PostgreSQL implements read-write separation (static strategy)
- MaxCompute 的SQL 引擎参数化视图具体有哪些增强功能?
- Five data structures of Redis and their corresponding usage scenarios
- openlayers版本更新差别
- 姑姑:给小学生出点口算题
- 你想要的宏基因组-微生物组知识全在这(2022.8)
- 笑话:如果你在河边等待得足够久,你会看到你的敌人的尸体漂过,是怎么翻译出来的?
猜你喜欢
Detailed explanation of common examples of dynamic programming
脑机接口003 | 马斯克称已实现与云端的虚拟自己对话,相关概念股份大涨
NC | Structure and function of soil microbiome reveal N2O release from global wetlands
SQL Server实现group_concat功能
Kali命令ifconfig报错command not found
光源控制器接口定义说明
SQL Server安装教程
PG's SQL execution plan
牛客题目——滑动窗口的最大值、矩阵最长递增路径、顺时针旋转矩阵、接雨水问题
什么是现场服务管理系统(FSM)?有什么好处?
随机推荐
光源控制器接口定义说明
分享一个 web 应用版本监测 (更新) 的工具库
Shell: conditional statements
ALV报表学习总结
PG 之 SQL执行计划
In action: 10 ways to implement delayed tasks, with code!
J9 digital theory: the Internet across chain bridge has what effect?
【StoneDB性能相关工具】内存监控
ShardingSphere-proxy +PostgreSQL implements read-write separation (static strategy)
SCANIA SCANIA OTL tag is introduced
MaxCompute 近期发布上线的版本的 SQL 引擎新功能参数化视图有什么优势?
SQL 嵌套 N 层太长太难写怎么办?
SQL 入门之第一讲——MySQL 8.0.29安装教程(windows 64位)
Redis 5 种数据结构及对应使用场景
【LeetCode】1374. 生成每种字符都是奇数个的字符串
image could not be accessed on a registry to record its digest
MaxCompute 的SQL 引擎参数化视图具体有哪些增强功能?
golang刷leetcode 经典(13) 最小高度树
磁盘分区的知识
MySQL安装(详细,适合小白)