Day21浮动

news/2026/1/20 23:07:00/文章来源:https://www.cnblogs.com/bingzhuo/p/19223651

1.浮动的基本使用

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>浮动的基本使用</title><style>/* 特点:顶对齐,具备行内块显示模式,即可以在同一行一起显示 */.one{width: 100px;height: 100px;background-color: red;float: left;}.two{width: 200px;height: 200px;background-color: orange;/* float: left; *//* float: right; *//* 此时由于只有.one进行了浮动,而浮动会导致该标签脱标 *//* 即浏览器不在会识别他为标签,后面的标签可能会抢占原本浮动标签的位置 *//* 导致标签重叠错乱 */}</style>
</head>
<body><div class="one"></div><div class="two"></div>
</body>
</html>

image

2.产品区域布局

<!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;}li{list-style: none;}.product{margin: 50px auto;width: 1226px;height: 628px;background-color: pink;}.left{float: left;width: 234px;height: 628px;background-color: skyblue;}.right{float: right;width: 978px;height: 628px;background-color: brown;}.right li{float: left;margin-right: 14px;margin-bottom: 14px;width: 234px;height: 300px;background-color: orange;}/* 第四个和第八个li去掉右边的margin */.right li:nth-child(4n){margin-right: 0;}/* 如果父级的宽度不够,即使加上了浮动,浮动的标签也可能因为位置不够而被挤到下一行 */</style>
</head>
<body><div class="product"><div class="left"></div><div class="right"><ul><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li></ul></div></div>
</body>
</html>

image

3.清除浮动异常
image
原理就是标签添加浮动属性之后会导致脱标,即浏览器不在为该标签安排位置,所以下一个标签会挤占浮动标签的位置,造成页面异常
例如:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>清除浮动异常</title><style>.top{margin: 10px auto;width: 1200px;/* 注释掉父级的高度,子集无法撑开父级高度,会导致页面错乱 *//* height: 300px; */background-color: pink;}.right{float: left;width: 200px;height: 300px;background-color: skyblue;}.left{float: right;width: 950px;height: 300px;background-color: orange;}.bottom{height: 100px;background-color: brown;}</style>
</head>
<body><div class="top"><div class="left"></div><div class="right"></div></div><div class="bottom"></div>
</body>
</html>

image

解决浮动异常的四种方法
image
额外标签法,在出现异常的标签的基础上再添加一个标签

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>额外标签法</title><style>.top{margin: 10px auto;width: 1200px;/* 注释掉父级的高度,子集无法撑开父级高度,会导致页面错乱 *//* height: 300px; */background-color: pink;}.right{float: left;width: 200px;height: 300px;background-color: skyblue;}.left{float: right;width: 950px;height: 300px;background-color: orange;}.bottom{height: 100px;background-color: brown;}.clearfix{clear: both;}</style>
</head>
<body><div class="top"><div class="left"></div><div class="right"></div><div class="clearfix"></div></div><div class="bottom"></div>
</body>
</html>

image
单伪元素法

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>单伪元素法</title><style>.top{margin: 10px auto;width: 1200px;/* 注释掉父级的高度,子集无法撑开父级高度,会导致页面错乱 *//* height: 300px; */background-color: pink;}.right{float: left;width: 200px;height: 300px;background-color: skyblue;}.left{float: right;width: 950px;height: 300px;background-color: orange;}.bottom{height: 100px;background-color: brown;}.clearfix::after{content: "";display: block;clear: both;}</style>
</head>
<body><div class="top clearfix"><div class="left"></div><div class="right"></div></div><div class="bottom"></div>
</body>
</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>.top{margin: 10px auto;width: 1200px;/* 注释掉父级的高度,子集无法撑开父级高度,会导致页面错乱 *//* height: 300px; */background-color: pink;}.right{float: left;width: 200px;height: 300px;background-color: skyblue;}.left{float: right;width: 950px;height: 300px;background-color: orange;}.bottom{height: 100px;background-color: brown;}.clearfix::before,.clearfix::after {content: "";display: table;}.clearfix::after {clear: both;}</style>
</head>
<body><div class="top clearfix"><div class="left"></div><div class="right"></div></div><div class="bottom"></div>
</body>
</html>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/207119.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

KEYDIY KD B12-3 3-Button Ford Flip Key Remote - 5pcs/lot (Replacement for Ford Vehicles)

## Problem: Key Replacements for Ford Vehicles – A Costly and Time-Consuming Hassle For European and American automotive repair shops and Ford vehicle owners, replacing lost or damaged keys can feel l…

Spring AI Alibaba 项目源码学习(七)-Agent、BaseAgent、ReactAgent 分析

Agent、BaseAgent、ReactAgent 分析 请关注微信公众号:阿呆-bot 概述 本文档分析 Spring AI Alibaba Agent Framework 中的核心 Agent 类层次结构,包括 Agent 基类、BaseAgent 抽象类和 ReactAgent 具体实现,重点分…

fireworks

fireworks https://github.com/materialsproject/fireworks FireWorks stores, executes, and manages calculation workflows.Website (including documentation): https://materialsproject.github.io/fireworks/ He…

KEYDIY KD ZB28-3 Universal Hyundai Smart Remote Key (5pcs/lot) – Reliable Replacement

## Hyundai Smart Key Woes? Meet the KEYDIY KD ZB28-3 Universal Solution ### Problem: The Frustration of Hyundai Smart Key Replacement When a Hyundai owner’s smart remote key fails, or a mechanic need…

Yanhua Mini ACDP-2 A303 Volvo 2022+ IMMO License for ACDP-2 Module20

**Tackling Modern Volvo IMMO Challenges: The Yanhua Mini ACDP-2 A303 License** Modern Volvo vehicles (2022 and newer) are equipped with advanced Immobilizer (IMMO) systems designed to enhance security.…

西电TIC带鱼杯新生训练赛复盘

传送门 A 最大子树和 P1122 最大子树和 - 洛谷几天前看过一眼,大概知道思路,但是因为忘记ans可能取负而没有一次切掉分析题目要求一个节点带权的树的最大子树和我们用 f [ i ]记录子树以节点 i 为根节点时的最大子树…

C++篇(13)计算器实现 - 指南

C++篇(13)计算器实现 - 指南2025-11-15 22:58 tlnshuju 阅读(0) 评论(0) 收藏 举报pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !importan…

20232306 2025-2026-1 《网络与系统攻防技术》实验五实验报告

1.实验要求 (1)从www.besti.edu.cn、baidu.com、sina.com.cn中选择一个DNS域名进行查询,获取如下信息: DNS注册人及联系方式 该域名对应IP地址 IP地址注册人及联系方式 IP地址所在国家、城市和具体地理位置 PS:使…

完整教程:linux离线环境局域网远程ssh连接vscode

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

第26天(简单题中等题 二分查找、贪心算法)

打卡第二十六天 1道简单题+2道中等题题目:思路: 贪心+二分查找,维护一个"潜在的最优递增序列集合",让每个长度的递增子序列的末尾元素尽可能小,从而为后续元素提供更多的增长可能性。代码: class Solution…

byd秘钥 - MKT

byd秘钥 https://rcorex.github.io/nuttyb-config/

【服务器】服务器被攻击植入了挖矿病毒,CPU一直占用100%,@monthly /root/.cfg/./dealer病毒清除 - 实践

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

牛客101:链表 - 教程

牛客101:链表 - 教程2025-11-15 22:39 tlnshuju 阅读(0) 评论(0) 收藏 举报pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-…

完整教程:Redis 事务机制:Pipeline、ACID、Lua脚本

完整教程:Redis 事务机制:Pipeline、ACID、Lua脚本pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas&quo…

银行核心账户体系、账务设计、会计核心(整合版)

开头先和读过的朋友道个歉,因为某些原因(​先不说​),文章需要重新发一遍,同时新发的内容有大幅增加,请仔细阅读不要遗漏。结合以前发过很多相关知识,今天将科目、账户、账务、会计串起来讲一讲,让整个知识体系…

银行中外汇的由来(金融产品经理必读)

经常听到我们国家有多少多少亿美元的外汇储备,是否有这样的疑问,外汇储备是什么,它又是怎么来的,银行又是如何处理外汇储备的,今天就闲聊一下。 外汇管理 常见概念 现汇: 通俗来讲,就是在银行账户里可以自由买卖…

AI元人文框架:意义世界的探索引擎

AI元人文框架:意义世界的探索引擎基础层:价值原语 •定义:将复杂人类现象分解为基本价值单元(如【公平】【忠诚】【卓越】) •作用:构建意义世界的"化学元素周期表",实现价值的解析与重组环境层:多维…

20232310 2025-2026-1 《网络与系统攻防技术》实验五实验报告

1.实验内容 1.1域名与IP信息搜集分析;1.2社交网络IP地址获取与地理位置定位;1.3靶机环境扫描探测、漏洞评估与攻击路径分析;1.4搜索个人网上足迹与高级搜索技能实践。2.实验目的 学习使用搜索引擎、扫描引擎、扫描工…

[MySQL] 基础操控

[MySQL] 基础操控2025-11-15 21:55 tlnshuju 阅读(0) 评论(0) 收藏 举报pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-fami…

AI元人文:悟空继续追问

AI元人文:悟空继续追问 —— 一个文明伙伴的诞生宣言 引言:从“工具”到“伙伴”的范式革命 当人工智能学会“追问”,文明的进程将被重新定义。我们正站在一个历史拐点:AI不再仅是执行命令的工具,而是正在成为能够…