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

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

相关文章

Java中流式并行操作parallelStream的原理和使用方法

《Java中流式并行操作parallelStream的原理和使用方法》本文详细介绍了Java中的并行流(parallelStream)的原理、正确使用方法以及在实际业务中的应用案例,并指出在使用并行流... 目录Java中流式并行操作parallelStream0. 问题的产生1. 什么是parallelS

MySQL数据库双机热备的配置方法详解

《MySQL数据库双机热备的配置方法详解》在企业级应用中,数据库的高可用性和数据的安全性是至关重要的,MySQL作为最流行的开源关系型数据库管理系统之一,提供了多种方式来实现高可用性,其中双机热备(M... 目录1. 环境准备1.1 安装mysql1.2 配置MySQL1.2.1 主服务器配置1.2.2 从

Python版本信息获取方法详解与实战

《Python版本信息获取方法详解与实战》在Python开发中,获取Python版本号是调试、兼容性检查和版本控制的重要基础操作,本文详细介绍了如何使用sys和platform模块获取Python的主... 目录1. python版本号获取基础2. 使用sys模块获取版本信息2.1 sys模块概述2.1.1

Python实现字典转字符串的五种方法

《Python实现字典转字符串的五种方法》本文介绍了在Python中如何将字典数据结构转换为字符串格式的多种方法,首先可以通过内置的str()函数进行简单转换;其次利用ison.dumps()函数能够... 目录1、使用json模块的dumps方法:2、使用str方法:3、使用循环和字符串拼接:4、使用字符

Python版本与package版本兼容性检查方法总结

《Python版本与package版本兼容性检查方法总结》:本文主要介绍Python版本与package版本兼容性检查方法的相关资料,文中提供四种检查方法,分别是pip查询、conda管理、PyP... 目录引言为什么会出现兼容性问题方法一:用 pip 官方命令查询可用版本方法二:conda 管理包环境方法

Linux云服务器手动配置DNS的方法步骤

《Linux云服务器手动配置DNS的方法步骤》在Linux云服务器上手动配置DNS(域名系统)是确保服务器能够正常解析域名的重要步骤,以下是详细的配置方法,包括系统文件的修改和常见问题的解决方案,需要... 目录1. 为什么需要手动配置 DNS?2. 手动配置 DNS 的方法方法 1:修改 /etc/res

JavaScript对象转数组的三种方法实现

《JavaScript对象转数组的三种方法实现》本文介绍了在JavaScript中将对象转换为数组的三种实用方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友... 目录方法1:使用Object.keys()和Array.map()方法2:使用Object.entr

pycharm跑python项目易出错的问题总结

《pycharm跑python项目易出错的问题总结》:本文主要介绍pycharm跑python项目易出错问题的相关资料,当你在PyCharm中运行Python程序时遇到报错,可以按照以下步骤进行排... 1. 一定不要在pycharm终端里面创建环境安装别人的项目子模块等,有可能出现的问题就是你不报错都安装

SpringBoot中ResponseEntity的使用方法举例详解

《SpringBoot中ResponseEntity的使用方法举例详解》ResponseEntity是Spring的一个用于表示HTTP响应的全功能对象,它可以包含响应的状态码、头信息及响应体内容,下... 目录一、ResponseEntity概述基本特点:二、ResponseEntity的基本用法1. 创

java中判断json key是否存在的几种方法

《java中判断jsonkey是否存在的几种方法》在使用Java处理JSON数据时,如何判断某一个key是否存在?本文就来介绍三种方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的... 目http://www.chinasem.cn录第一种方法是使用 jsONObject 的 has 方法