三栏布局----方法总结

2023-10-19 17:59
文章标签 总结 方法 布局 三栏

本文主要是介绍三栏布局----方法总结,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

三栏布局介绍:

三栏布局,顾名思义就是两边固定宽度,中间内容宽度岁浏览器宽度自适应。如,打开某东首页:



三栏布局方法:

方法一:浮动布局

注:  浮动元素脱离了文档流,根据实际情况使用时清除浮动。 

<!DOCTYPE html>
<html lang="en">
<head><style>h1 {text-align: center;}.container {width: 100%;height: 200px;}.left {width: 200px;height: 100%;background-color: red;float: left;}.right {width: 200px;height: 100%;background-color: red;float: right;}.main {height: 100%;margin-left: 200px;margin-right: 200px;background-color: yellow;}</style>
</head>
<body><h1>三栏布局---第一种浮动布局</h1><div class="container"><div class="left"></div><div class="right"></div><div class="main"></div></div>
</body>
</html>
方法二:绝对定位布局
简单实用,并且主要内容可以优先加载。

<!DOCTYPE html>
<html lang="en">
<head><style>h1 {text-align: center;}.container {width: 100%;height: 200px;position: relative;}.left {width: 200px;height: 100%;background-color: red;position: absolute;left: 0;top: 0;}.right {width: 200px;height: 100%;background-color: red;position: absolute;right: 0;top: 0;}.main {height: 100%;margin-left: 200px;margin-right: 200px;background-color: yellow;}</style>
</head>
<body><h1>三栏布局---第二种绝对定位布局</h1><div class="container"><div class="left"></div><div class="right"></div><div class="main"></div></div>
</body>
</html>
方法三:BFC布局

注:BFC 规则有这样的描述:BFC 区域,不会与浮动元素重叠。因此我们可以利用这一点来实现 3 列布局。缺点:主要内容模块无法最先加载,当页面中内容较多时会影响用户体验。因此为了解决这个问题,有了下面要介绍的布局方案双飞翼布局。


<!DOCTYPE html>
<html lang="en">
<head><style>h1 {text-align: center;}.container {width: 100%;height: 200px;}.left {width: 200px;height: 100%;background-color: red;float: left;}.right {width: 200px;height: 100%;background-color: red;float: right;}.main {height: 100%;overflow: hidden;background-color: yellow;}</style>
</head>
<body><h1>三栏布局---第三种BFC(块级格式上下文)布局</h1><div class="container"><div class="left"></div><div class="right"></div><div class="main"></div></div>
</body>
</html>
方法四:双飞翼布局

主体内容可以优先加载,HTML 代码结构稍微复杂点。


<!DOCTYPE html>
<html lang="en">
<head><style>.content {float: left;width: 100%;}.main {height: 200px;margin-left: 200px;margin-right: 200px;background-color: green;}.left {float: left;height: 200px;width: 200px;margin-left: -100%;background-color: red;}.right {width: 200px;height: 200px;float: right;margin-left: -200px;background-color: blue;}</style>
</head>
<body><h1>三栏布局---第四种双飞翼布局</h1><div class="content"><div class="main"></div></div><div class="left"></div><div class="right"></div>
</body>
</html>
方法五:圣杯布局

和双飞翼布局很像,有一些细节上的区别,相对于双飞翼布局来说,HTML 结构相对简单,但是样式定义就稍微复杂,也是优先加载内容主体。


<!DOCTYPE html>
<html lang="en">
<head><style>.container {margin-left: 200px;margin-right: 200px;}.main {float: left;width: 100%;height: 200px;background-color: red;}.left {float: left;width: 200px;height: 200px;margin-left: -100%;position: relative;left: -200px;background-color: blue;}.right {float: left;width: 200px;height: 200px;margin-left: -200px;position: relative;right: -200px;background-color: green;}</style>
</head>
<body><h1>三栏布局---第五种圣杯布局</h1><div class="container"><div class="main"></div><div class="left"></div><div class="right"></div></div>
</body>
</html>
方法六:flex布局

需要考虑浏览器的兼容性

<!DOCTYPE html>
<html lang="en">
<head><style>.container {display: flex;}.main {flex-grow: 1;height: 200px;background-color: red;}.left {order: -1;flex: 0 1 200px;height: 200px;background-color: blue;}.right {flex: 0 1 200px;height: 200px;background-color: green;}</style>
</head>
<body><h1>三栏布局---第六种flex布局</h1><div class="container"><div class="main"></div><div class="left"></div><div class="right"></div></div>
</body>
</html>
方法七:表格布局

缺点:无法设置栏间距

<!DOCTYPE html>
<html lang="en">
<head><style>.container {display: table;width: 100%;}.left,.main,.right {display: table-cell;}.left {width: 200px;height: 200px;background-color: red;}.main {background-color: blue;}.right {width: 200px;height: 200px;background-color: green;}</style>
</head>
<body><h1>三栏布局---第七种表格布局</h1><div class="container"><div class="left"></div><div class="main"></div><div class="right"></div></div>
</body>
</html>

以上是我整理的关于三栏布局的方法,欢迎大家补充。提出问题。谢谢。


这篇关于三栏布局----方法总结的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/241430

相关文章

Conda与Python venv虚拟环境的区别与使用方法详解

《Conda与Pythonvenv虚拟环境的区别与使用方法详解》随着Python社区的成长,虚拟环境的概念和技术也在不断发展,:本文主要介绍Conda与Pythonvenv虚拟环境的区别与使用... 目录前言一、Conda 与 python venv 的核心区别1. Conda 的特点2. Python v

Spring Boot中WebSocket常用使用方法详解

《SpringBoot中WebSocket常用使用方法详解》本文从WebSocket的基础概念出发,详细介绍了SpringBoot集成WebSocket的步骤,并重点讲解了常用的使用方法,包括简单消... 目录一、WebSocket基础概念1.1 什么是WebSocket1.2 WebSocket与HTTP

SQL Server配置管理器无法打开的四种解决方法

《SQLServer配置管理器无法打开的四种解决方法》本文总结了SQLServer配置管理器无法打开的四种解决方法,文中通过图文示例介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的... 目录方法一:桌面图标进入方法二:运行窗口进入检查版本号对照表php方法三:查找文件路径方法四:检查 S

MyBatis-Plus 中 nested() 与 and() 方法详解(最佳实践场景)

《MyBatis-Plus中nested()与and()方法详解(最佳实践场景)》在MyBatis-Plus的条件构造器中,nested()和and()都是用于构建复杂查询条件的关键方法,但... 目录MyBATis-Plus 中nested()与and()方法详解一、核心区别对比二、方法详解1.and()

golang中reflect包的常用方法

《golang中reflect包的常用方法》Go反射reflect包提供类型和值方法,用于获取类型信息、访问字段、调用方法等,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值... 目录reflect包方法总结类型 (Type) 方法值 (Value) 方法reflect包方法总结

C# 比较两个list 之间元素差异的常用方法

《C#比较两个list之间元素差异的常用方法》:本文主要介绍C#比较两个list之间元素差异,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录1. 使用Except方法2. 使用Except的逆操作3. 使用LINQ的Join,GroupJoin

MySQL查询JSON数组字段包含特定字符串的方法

《MySQL查询JSON数组字段包含特定字符串的方法》在MySQL数据库中,当某个字段存储的是JSON数组,需要查询数组中包含特定字符串的记录时传统的LIKE语句无法直接使用,下面小编就为大家介绍两种... 目录问题背景解决方案对比1. 精确匹配方案(推荐)2. 模糊匹配方案参数化查询示例使用场景建议性能优

关于集合与数组转换实现方法

《关于集合与数组转换实现方法》:本文主要介绍关于集合与数组转换实现方法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、Arrays.asList()1.1、方法作用1.2、内部实现1.3、修改元素的影响1.4、注意事项2、list.toArray()2.1、方

Python中注释使用方法举例详解

《Python中注释使用方法举例详解》在Python编程语言中注释是必不可少的一部分,它有助于提高代码的可读性和维护性,:本文主要介绍Python中注释使用方法的相关资料,需要的朋友可以参考下... 目录一、前言二、什么是注释?示例:三、单行注释语法:以 China编程# 开头,后面的内容为注释内容示例:示例:四

JavaSE正则表达式用法总结大全

《JavaSE正则表达式用法总结大全》正则表达式就是由一些特定的字符组成,代表的是一个规则,:本文主要介绍JavaSE正则表达式用法的相关资料,文中通过代码介绍的非常详细,需要的朋友可以参考下... 目录常用的正则表达式匹配符正则表China编程达式常用的类Pattern类Matcher类PatternSynta