当前位置:网站首页>盒子模型大详解
盒子模型大详解
2022-08-05 05:25:00 【Y-琼眸】
文档流
网页是一个多层结构,设置样式也是一层一层设置的,最终我们看到的是最上面的那一层,文档流就是网页最底部。我们创建的元素默认都是在文档流中创建的
元素分为两种状态:在文档流 脱离文档流
元素在文档流的特点
块元素
1.独占一行
2.宽是父元素的100%
3.高被内容撑开
行内元素
1.不会独占一行
2.宽高被内容撑开,不能定义宽高
如果元素脱离文档流后,就不再区分块元素,行内元素,行内块元素
那么元素该如何脱离文档流呢?
我们可以采用浮动、绝对定位、flex布局 等等方法来操作
盒子模型
接下来我们来看看今天的重点盒子模型!
盒子模型是什么呢?可能很多人都抱有这样的疑问,那么今天就来讲讲盒子模型。
盒子模型顾名思义就是一个盒子就是一个矩形,英文名box model。
盒子模型主要包含内容区、边框、内边距、外边距。假如说你买了一个冰箱,那么快递寄过来的那一个大纸箱就是一个盒子。冰箱就是内容区,包裹冰箱的泡沫就是内边距,纸箱就是边框,而纸箱到你的距离则成为外边距。
内容区content
元素中所有子元素和文本内容都在内容区排列
width 设置宽
height 设置高
边框border
给元素设置边框,边框是盒子的边缘
边框里必须要指定三个东西:样式 大小 颜色
border-top上边框
border-left左边框
border-right右边框
border-bottom下边框
首先我们来说一下颜色
border-color: red;
不写默认颜色为黑色
可以写多个颜色 四个颜色 上 右 下 左
三个颜色 上 左右 下
两个颜色 上下 左右
一个颜色 上下左右
简写:border-top/right/left/bottom-color: ;
接下来看一下大小
border-width: 10px;
默认值为1-3px
可以写多个值 四个大小 上 右 下 左
三个大小 上 左右 下
两个大小 上下 左右
一个大小 上下左右
这个跟颜色是一样的。
下面是样式
border-style: solid;
默认值none
solid实线
dashed虚线
dotted点线
double双实线
这些大家一定要详记!
内边距padding
内边距是内容区到边框的距离
padding-top 上内边距
padding-right 右内边距
padding-left 左内边距
padding-bottom 下内边距
这个非常简单,大家就看一看下面的代码就好了
<style>
.box1{
width: 200px;
height: 200px;
border: 10px green solid;
background-color: aqua;
padding-left: 30px;
padding-top: 30px;
padding-bottom: 30px;
padding-right: 30px;
/* 简写 padding: 30px;
可以写 四个值 三个字 两个值 一个值
规则根边框里的颜色 大小一样
*/
}
边栏推荐
- Autoware--Beike Tianhui rfans lidar uses the camera & lidar joint calibration file to verify the fusion effect of point cloud images
- DevOps流程demo(实操记录)
- Network Protocol Fundamentals - Study Notes
- 网络协议基础-学习笔记
- What is the website ICP record?
- 单片机原理与应用复习
- Drools规则引擎快速入门(一)
- [ingress]-ingress exposes services using tcp port
- Mina disconnects and reconnects
- Passing parameters in multiple threads
猜你喜欢
Error correction notes for the book Image Processing, Analysis and Machine Vision
LaTeX 图片加标题 文本分栏自动换行
cs231n learning record
多行文本省略
LaTeX image captioning text column automatic line wrapping
The use of three parameters of ref, out, and Params in Unity3D
数组&的运算
Writing OpenCV in VSCode
ev加密视频转换成MP4格式,亲测可用
[Problem has been resolved]-Virtual machine error contains a file system with errors check forced
随机推荐
农场游戏果园系统+牧场养殖系统+广告联盟模式流量主游戏小程序APP V1
Shadowless Cloud Desktop
vscode notes
Native JS takes you to understand the implementation and use of array methods
网络协议基础-学习笔记
cs231n学习记录
js判断文字是否超过区域
Drools规则引擎快速入门(一)
unity 将Text批量替换为TextMeshProUGUI
[issue resolved] - jenkins pipeline checkout timeout
input detailed file upload
Met with the browser page
cs231n learning record
初识网页与浏览器
LaTeX 图片加标题 文本分栏自动换行
ALC experiment
浏览器存储WebStorage
The cocos interview answers you are looking for are all here!
设置文本向两边居中展示
Browser Storage WebStorage