Day21浮动

news/2025/11/15 23:26:05/文章来源: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.mzph.cn/news/966575.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈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 具体实现,重点分…

AtCoder Beginner Contest 432 ABCDEG 题目解析

A - Permute to Maximize 题意 给定三个个位数 \(A,B,C\)。 请找出将 \(A,B,C\) 按任意顺序排列并连接起来可以形成的所有三位数中的最大值。 思路 贪心可知,当数字长度一定时,可以优先让高位更大。因此对三个正整数…

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 为根节点时的最大子树…

20251115 - 从零到1详细剖析STM32的CAN架构【以STM32F407为例】

从零到1详细剖析STM32的CAN架构【以STM32F407为例】 1 概览:bxCAN 在 STM32F407 中的位置与作用bxCAN(Basic extended CAN) 是 STM32F4 系列内部实现的 CAN 控制器硬件 IP,用来在物理 CAN 差分总线上收/发 CAN 帧(…

2025.11.15 测试

2025.11.15 测试改题 策略 7:10 顺序开题 T1 随便猜了个结论然后不小心过了大杨利,还好这种题我有经验,没有被吓到 7:49 写完 full_speed 说这个是模板快速读入 因为他写快读但没用,T 到 35pt。。。 T2 额,一眼数…

鸿蒙应用审核被拒?常见原因与避坑指南来了

一个个精心开发的应用,却总在审核关卡折戟,问题究竟出在哪里?鸿蒙生态正迎来前所未有的爆发期。数据显示,HarmonyOS 5 终端数已突破 2300 万,鸿蒙开发者数量超过 800 万,上架应用及元服务超过 3 万款。 在“鸿蒙…

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:使…

ABC432E sol

eazy ds problem. 题意 给你一个序列 $a$,需要支持单点加 & 全局求 $\max\left(l,\min(r,a_i)\right)$(也就是对于每个 $a_i$,当 $a_i<l$,造成 $l$ 的贡献;当 $a_i \ge r$ 时,造成 $r$ 的贡献;否则造成 …

完整教程: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", …

2025 CSP-S 趋势记

“去年 CSP-S 就没过初赛,今年呢?” 2025 CSP-S 寄。 T1 60min才发现可以反悔贪心,跑完大样例觉得是对的然后有个等号少判了就 100 -> 65。 T2 连正解都没想出来,只会 \(O(2^k \times (m + nk) + (m + nk) \log…

鲜花:记梦4

“你考虑得怎么样了?” 对面的声音打断了我的思考。我抬头一看,居然是,她。 我竭力克制住我的情绪变化,把悸动深深藏在了心底。 她递给我一个信封:“如果考虑好了的话,就在里面的合同上签字吧。”我连忙伸手去接…

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

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

invalid literal for int() with base 10: abc中的base 10是什么意思? 另外它是怎么知道abc的?

在 Python 错误信息 invalid literal for int() with base 10: abc 中,涉及两个关键问题:base 10 的含义,以及程序如何知道错误输入是 abc。下面分别详细解释: 一、base 10 是什么意思? base 在这里表示“进制”,…

byd秘钥 - MKT

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