盒子模型
说起盒子模型,就想到:盒子实际大小=width+padding+border。
在CSS3盒子模型中,除了这种计算方式外,还有另外一种。一种不会被padding撑大的盒子模型计算公式。
语法
box-sizing:content-box | border-box;
- content-box:盒子模型的宽高=width/height +padding+border。
代码练习
原来学习的盒子模型大小:width+padding+border
* {
margin: 0;
padding: 0;
}
.box1 {
width: 200px;
height: 200px;
padding: 5px;
border: 5px solid black;
margin-bottom: 5px;
box-sizing: content-box; /* width+padding+border */
}
content-box
content-box:盒子宽度=width+padding+border
- border-box:盒子模型的宽高=width/height。
CSS3的盒子模型:width
.box2 {
width: 200px;
height: 200px;
padding: 5px;
border: 5px solid black;
box-sizing: border-box;
}
border-box
border-box:盒子宽度=width
图片模糊
当鼠标悬停在图片时,给图片添加模糊效果。
语法
filter: blur(px);
像素值越大,图片越模糊。
代码练习

.blur {
/* 像素值越大,图片越模糊。 */
filter: blur(5px);
}
函数公式
计算公式,如宽高的加减乘除。
语法
width | height:calc(num1 - num2);
代码练习
.boxF {
width: 200px;
height: 200px;
background-color: bisque;
}
.boxS {
/* 不论父级元素的width值是多少,子元素的width永远比父级元素少30px。 */
width: calc(100% - 30px);
height: 30px;
background-color: aqua;
}
过渡
使用CSS代码,当元素从一种样式转换成另一种样式时添加样式效果。
语法
transition:变化的属性 花费时间 运动曲线 何时开始;
代码练习
统一HTML代码结构
默认盒子
盒子的宽度变宽过渡
盒子的宽和高一起过渡
盒子的所有属性一起过渡
div {
width: 200px;
height: 100px;
background-color: bisque;
margin-bottom: 10px;
}
/* 1.修改一种样式的过渡效果 */
.box1 {
/*
transition:变化的属性 花费时间 运动曲线 何时开始;
其中运动曲线默认ease,开始时间默认0s,可不用设置。
*/
/* transition: width .5s ease 0s; */
transition: width .5s;
}
.box1:hover {
width: 400px;
}
/* 2. 修改两种或多种样式的过渡效果 */
.box2 {
/* 两种样式之间使用逗号隔开 */
transition: width .5s,height .5s;
}
.box2:hover {
width: 400px;
height: 200px;
}
/* 3. 修改全部样式的过渡效果 使用all */
.box3 {
transition: all .5s;
}
.box3:hover {
width: 400px;
height: 200px;
background-color: aqua;
}
实操小案例:进度条
.demo {
width: 150px;
height: 15px;
border: 1px solid red;
padding: 1px;
border-radius: 7px;
}
.demoBox {
width: 50%;
height: 100%;
background-color: red;
border-radius: 7px;
transition: width .5s;
}
.demoBox:hover {
width: 100%;
}
昨天发布没成功,老是审核失败,不知道原因在哪。