当前位置:网站首页>盒子模型中过度约束问题及其解决办法
盒子模型中过度约束问题及其解决办法
2022-08-05 05:25:00 【Y-琼眸】
盒子模型就是用来布局的,之前已经讲了盒子模型的基本内容,接下来我们就来看看用盒子模型进行水平布局时遇到的一个问题——过度约束问题。
<body>
<div class="box1">
<div class="box2"></div>
</div>
</body>首先我们先建立两个盒子box1 box2,然后我们给这两个盒子设置样式,如下图
<style>
.box1{
width: 600px;
height: 200px;
border: 10px red solid;
}
.box2{
width: 100px;
height: 100px;
background-color: aqua;
padding: 0 20px;
margin: 0 10px;
}
</style>这样我们就得到了两个不一样的盒子。
我们来先看看能改变box2的水平方向大小位置的一些属性
有下列七个属性:margin-left、border-left、padding-left、width、padding-right、border-right、margin-right
浏览器规定,水平方向七个值相加必须等于其父元素内容区的宽度,如果不等于,浏览器会自动调整七个值中的一个值让其成立,这就是过度约束。
这个时候我们看看上面那串代码,七个值的和为20+10+10+100+10+10+20=180,这并不等于我们的父元素600,所以浏览器就会自动调整一个值让它们成立。
那么下来我们就来看看浏览器是如何调整的。
1.七个值中如果没有auto,那么浏览器默认调整margin-right
2.七个值中如果有auto,那么浏览器就调整auto
可以设置auto的属性有margin-right width margin-left
(1)一个auto,谁是auto就调整谁
(2)两个auto,只要width为auto就调整width
margin-right width为auto margin-left固定值 浏览器调整width
margin-right margin-left为auto width固定值 浏览器同时调整margin-left 和margin-right,距离平分,盒子居中显示
margin-left width为auto margin-right固定值 浏览器调整width
(3)三个auto,调整width
总的来说,浏览器要调整,肯定优先调整width。
边栏推荐
- What is the website ICP record?
- ES2020新特性
- DevOps - Understanding Learning
- From "dual card dual standby" to "dual communication", vivo took the lead in promoting the implementation of the DSDA architecture
- js判断文字是否超过区域
- What is Alibaba Cloud Express Beauty Station?
- Programmers should understand I/O this way
- Nacos配置服务的源码解析(全)
- May I ask how to read the binlog of the two tables of hologres through flink sql, and then how to join?
- Alibaba Cloud Video on Demand
猜你喜欢

Nacos配置服务的源码解析(全)

Detailed explanation of the construction process of Nacos cluster

图像处理、分析与机器视觉一书纠错笔记

UI刘海屏适配方式

Error correction notes for the book Image Processing, Analysis and Machine Vision

System basics - study notes (some command records)

Writing OpenCV in VSCode
![[Problem has been resolved]-Virtual machine error contains a file system with errors check forced](/img/07/1222a44dd52b359bf7873e6f3b7ebf.png)
[Problem has been resolved]-Virtual machine error contains a file system with errors check forced
![[问题已处理]-虚拟机报错contains a file system with errors check forced](/img/07/1222a44dd52b359bf7873e6f3b7ebf.png)
[问题已处理]-虚拟机报错contains a file system with errors check forced

selenium学习
随机推荐
What is Alibaba Cloud Express Beauty Station?
Mina disconnects and reconnects
The method of using ROS1 bag under ROS2
Detailed explanation of the construction process of Nacos cluster
D46_Force applied to rigid body
disabledDate 日期选择器 datePicker
GetEnumerator method and MoveNext and Reset methods in Unity
Does flink cdc currently support Gauss database sources?
Error correction notes for the book Image Processing, Analysis and Machine Vision
transport layer protocol
D39_ coordinate transformation
selenium学习
[ingress]-ingress exposes services using tcp port
亚马逊美国站:马术头盔CPC认证标准要求
Network Protocol Fundamentals - Study Notes
DevOps-了解学习
el-progress实现进度条颜色不同
LeetCode练习及自己理解记录(1)
LaTeX使用frame制作PPT图片没有标号
DevOps流程demo(实操记录)