当前位置:网站首页>盒子模型中过度约束问题及其解决办法
盒子模型中过度约束问题及其解决办法
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。
边栏推荐
- el-autocomplete使用
- 七种让盒子水平垂直居中的方法
- Error correction notes for the book Image Processing, Analysis and Machine Vision
- document.querySelector()方法
- 滚动条问题,未解决
- 图像处理、分析与机器视觉一书纠错笔记
- 大小屏适配
- In-depth analysis if according to data authority @datascope (annotation + AOP + dynamic sql splicing) [step by step, with analysis process]
- Some basic method records of commonly used languages in LeetCode
- 原生JS带你了解数组方法实现及使用
猜你喜欢

多用户商城多商户B2B2C拼团砍价秒杀支持小程序H5+APP全开源

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

Take you in-depth understanding of cookies

获取预训练模型的网络输入尺寸

sql server duplicate values are counted after

Tencent Internal Technology: Evolution of Server Architecture of "The Legend of Xuanyuan"

Successful indie developers deal with failure & imposters

NB-IOT智能云家具项目系列实站

config.js相关配置汇总

selenium模块的操作之拉钩
随机推荐
cs231n学习记录
【FAQ】What is Canon CCAPI
多用户商城多商户B2B2C拼团砍价秒杀支持小程序H5+APP全开源
input详解之文件上传
el-autocomplete use
The use of three parameters of ref, out, and Params in Unity3D
NB-IOT智能云家具项目系列实站
Collection of error records (write down when you encounter them)
Mina's long and short connections
[Problem has been resolved]-Virtual machine error contains a file system with errors check forced
Late night drinking, 50 classic SQL questions, really fragrant~
numpy.random使用文档
Shadowless Cloud Desktop
Autoware--Beike Tianhui rfans lidar uses the camera & lidar joint calibration file to verify the fusion effect of point cloud images
vscode笔记
LeetCode练习及自己理解记录(1)
大小屏适配
The size of the screen adaptation
Detailed explanation of the construction process of Nacos cluster
单片机期末复习大题