当前位置:网站首页>盒子模型中过度约束问题及其解决办法
盒子模型中过度约束问题及其解决办法
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。
边栏推荐
- LeetCode practice and self-comprehension record (1)
- ev加密视频转换成MP4格式,亲测可用
- UI刘海屏适配方式
- LaTeX笔记
- D39_ coordinate transformation
- Cloud Computing Basics - Study Notes
- Error correction notes for the book Image Processing, Analysis and Machine Vision
- Chengyun Technology was invited to attend the 2022 Alibaba Cloud Partner Conference and won the "Gathering Strength and Going Far" Award
- Quick Start to Drools Rule Engine (1)
- Cocos Creator Mini Game Case "Stick Soldier"
猜你喜欢
vs2017关于函数命名方面的注意事项
The use of three parameters of ref, out, and Params in Unity3D
NAT experiment
[Problem has been resolved]-Virtual machine error contains a file system with errors check forced
LaTeX image captioning text column automatic line wrapping
el-progress实现进度条颜色不同
单片机原理与应用复习
scikit-image image processing notes
DevOps - Understanding Learning
input详解之文件上传
随机推荐
农场游戏果园系统+牧场养殖系统+广告联盟模式流量主游戏小程序APP V1
Next-Generation Parsing Technology - Cloud Parsing
scikit-image image processing notes
【FAQ】CCAPI兼容EOS相机列表(2022年8月 更新)
Writing OpenCV in VSCode
Q 2020, the latest senior interview Laya soul, do you know?
设置文本向两边居中展示
UI刘海屏适配方式
Mina disconnects and reconnects
花花省V5淘宝客APP源码无加密社交电商自营商城系统带抖音接口
ALC experiment
The hook of the operation of the selenium module
[Problem has been resolved]-Virtual machine error contains a file system with errors check forced
Into the pre-service, thought they play so flowers
Programmers should understand I/O this way
VLAN is introduced with the experiment
Media query, rem mobile terminal adaptation
link 和@improt的区别
document.querySelector()方法
H5开发调试-Fiddler手机抓包