赞
踩
伪元素添加动态效果,一般与过渡配合使用
改变盒子在平面内的形态(位移、旋转、缩放、倾斜)
平面转换又叫2D转换
transform:translate(x轴移动距离,y轴移动距离)
像素单位数值
正负均可
1.translate()只写一个值,表示沿着x轴移动
2.单独设置X或Y轴移动距离:translateX()或translateY()
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .father{ width: 500px; height: 300px; margin: 100px auto; border: 1px solid #000; } .son{ width: 200px; height: 100px; background-color: pink; transition: all 0.5s; } .father:hover .son{ transform: translate(200px,200px); } </style> </head> <body> <div class="father"> <div class="son"> </div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .father{ width: 500px; height: 300px; margin: 100px auto; border: 1px solid #000; } .son{ width: 200px; height: 100px; background-color: pink; transition: all 0.5s; } .father:hover .son{ transform: translate(50%,100%); } </style> </head> <body> <div class="father"> <div class="son"> </div> </div> </body> </html>
注:使用百分比的话,是相对于自身的宽和高
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .father{ width: 500px; height: 300px; margin: 100px auto; border: 1px solid #000; } .son{ width: 200px; height: 100px; background-color: pink; transition: all 0.5s; } .father:hover .son{ transform: translate(-50%,100%); } </style> </head> <body> <div class="father"> <div class="son"> </div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .father{ width: 500px; height: 300px; margin: 100px auto; border: 1px solid #000; } .son{ width: 200px; height: 100px; background-color: pink; transition: all 0.5s; } .father:hover .son{ transform: translate(100px); } </style> </head> <body> <div class="father"> <div class="son"> </div> </div> </body> </html>
注:只写一个值,只在水平方向移动(由于translatex(100px)与上面这个效果相同,便不再书写)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .father{ width: 500px; height: 300px; margin: 100px auto; border: 1px solid #000; } .son{ width: 200px; height: 100px; background-color: pink; transition: all 0.5s; } .father:hover .son{ transform: translatey(100px); } </style> </head> <body> <div class="father"> <div class="son"> </div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ width: 200px; height: 100px; background-color: pink; position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); } </style> </head> <body> <div class="box"></div> </body> </html>
transform:rotate(旋转角度) 单位:deg
取值正负均可
取值为正、顺时针旋转
取值为负、逆时针旋转
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> img{ width: 200px; transition: all 2s; } img:hover{ transform: rotate(360deg); } </style> </head> <body> <img src="./images/1.jpg" alt=""> </body> </html>
注:旋转角度为正,则顺时针旋转,旋转角度为负,则逆时针旋转
transform-origin:水平原点位置 垂直原点位置;
方位名词(left、top、right、bottom、center)
像素单位数值
百分比
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> img{ width: 200px; transition: all 2s; } img:hover{ transform: rotate(360deg); transform-origin:left top ; } </style> </head> <body> <img src="./images/1.jpg" alt=""> </body> </html>
先平移再旋转
transform:translate() rorate();
注:
1)旋转会改变坐标轴向
2)以第一种转化形态的坐标轴为准
3)想要边走边转动,必须这样书写,分开写样式会层叠,不能达到目标
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ width: 800px; height: 200px; border: 1px solid black; } img{ width: 200px; transition: all 2s; } .box:hover img{ transform: translate(600px) rotate(360deg); } </style> </head> <body> <div class="box"> <img src="./images/1.jpg" alt=""> </div> </body> </html>
transform:scale(缩放倍数);
transform:scale(x轴缩放倍数,y轴缩放倍数);
通常只为scale()设置一个值,表示x轴和y轴等比缩放
取值大于1表示放大,取值小于1表示缩小
取值小于1
![](https://vichywhite.oss-cn-beijing.aliyuncs.com/chenweiqi2023012226/202404030833553.png)
取值大于1
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ width: 800px; height: 200px; margin: 100px auto; } img{ width: 200px; transition: all 2s; } .box:hover img{ /* width: 500px; */ /* height: 400px; */ transform:scale(2); } </style> </head> <body> <div class="box"> <img src="./images/1.jpg" alt=""> </div> </body> </html>
注:如果取值为1,则大小不变化。
transform:skew();
角度度数deg
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ width: 800px; height: 200px; margin: 100px auto; } img{ width: 200px; transition: all 2s; } .box:hover img{ /* width: 500px; */ /* height: 400px; */ transform:skew(30deg); } </style> </head> <body> <div class="box"> <img src="./images/1.jpg" alt=""> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ width: 800px; height: 200px; margin: 100px auto; } img{ width: 200px; transition: all 2s; } .box:hover img{ /* width: 500px; */ /* height: 400px; */ transform:skew(-30deg); } </style> </head> <body> <div class="box"> <img src="./images/1.jpg" alt=""> </div> </body> </html>
渐变是多个颜色逐渐变化的效果,一般用于设置盒子背景
线性渐变
径向渐变
background-image:linear-gradient(渐变方向,颜色1 终点位置,颜色2 终点位置,.......)
注:位置可以省略
渐变方向:可选(to方位名词,角度度数)
终点位置:可选(百分比)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ width: 200px; height: 200px; background-color: green; background-image: linear-gradient( to right,red,green); } </style> </head> <body> <div></div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ width: 200px; height: 200px; background-color: green; background-image: linear-gradient( 45deg,red,green); } </style> </head> <body> <div></div> </body> </html>
渐变背景
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ width: 300px; height: 212px; position: relative; } img{ width: 300px; } .box .title{ position: absolute; left: 15; bottom: 20px; z-index: 2; width: 260px; color: white; font-size: 20px; font-weight: 700; } .mask{ width:300px; height: 230px; background-image: linear-gradient(transparent,rgba(0,0,0,0.5)); position: absolute; left: 0; top: 0; opacity: 0; transition: all .5s; } .box:hover .mask{ opacity: 1; } </style> </head> <body> <div class="box"> <img src="./images/1.jpg" alt=""> <div class="title"> 内容内容内容 </div> <div class="mask"></div> </div> </body> </html>
给按钮添加高光效果
background-image:radial-gradient(
半径 at 圆心位置,颜色1 终点位置,颜色2 终点位置,......);
半径可以是2条,则为椭圆
圆心位置取值:像素单位数值/百分比/方位名词
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ width: 100px; height: 100px; background-color: pink; border-radius: 50%; background-image: radial-gradient(50px at center center,red,pink); } button{ width: 100px; height: 40px; background-color: green; border: 0; border-radius: 5px; color: #fff; } </style> </head> <body> <div></div> <button></button> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ width: 100px; height: 100px; background-color: pink; border-radius: 50%; background-image: radial-gradient(50px 20px at center center,red,pink); } button{ width: 100px; height: 40px; background-color: green; border: 0; border-radius: 5px; color: #fff; } </style> </head> <body> <div></div> <button></button> </body> </html>
镜像渐变
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div{ width: 100px; height: 100px; background-color: pink; border-radius: 50%; background-image: radial-gradient(50px 20px at center center,red,pink); } button{ width: 100px; height: 40px; background-color: green; border: 0; border-radius: 5px; color: #fff; background-image: radial-gradient( 30px at 30px 20px ,rgba(255,255,255,0.2), transparent ); } </style> </head> <body> <div></div> <button>按钮</button> </body> </html>
at后面两个像素数值,先x轴后y轴
transform:translate3d(x,y,z)
transform:translateX()
transform:translateY()
transform:translateZ()
像素单位数值
百分比(参照盒子自身尺寸计算结果)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ width: 200px; height: 200px; margin: 100px auto; background-color: pink; transition: all 0.5s; } .box:hover{ transform: translate3d(100px,200px,300px); } </style> </head> <body> <div class="box"></div> </body> </html>
注:但是z轴效果看不见
制定了观察者与z=0平面的距离,为元素添加透视效果
透视效果:近大远小,近实远虚
添加给直接父级,取值范围800-1200
perspective:视距;
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .father{ perspective: 1000px; } .son{ width: 200px; height: 200px; margin: 100px auto; transition: all 0.5s; background-color: pink; } .son:hover{ transform: translateZ(-300px); } </style> </head> <body> <div class="father"> <div class="son"></div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .father{ perspective: 100px; } .son{ width: 200px; height: 200px; margin: 100px auto; transition: all 0.5s; background-color: pink; } .son:hover{ transform: translate3d(0,0,-100px); } </style> </head> <body> <div class="father"> <div class="son"></div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .father{ perspective: 2000px; } .son{ width: 200px; height: 200px; margin: 100px auto; transition: all 0.5s; background-color: pink; } .son:hover{ transform: translate3d(0,0,-100px); } </style> </head> <body> <div class="father"> <div class="son"></div> </div> </body> </html>
注:perspective的值过大过小都不易观察
transform-rotateZ(值);
transform-rotateX(值);
transform-rotateY(值);
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ width: 300px; margin: 100px auto; } img{ width: 300px; transition: all 2s; } .box{ perspective: 1000px; } .box img:hover{ transform: rotateZ(60deg); } </style> </head> <body> <div class="box"> <img src="./images/1.jpg" alt=""> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ width: 300px; margin: 100px auto; } img{ width: 300px; transition: all 2s; } .box{ perspective: 1000px; } .box img:hover{ transform: rotateX(60deg); } </style> </head> <body> <div class="box"> <img src="./images/1.jpg" alt=""> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ width: 300px; margin: 100px auto; } img{ width: 300px; transition: all 2s; } .box{ perspective: 1000px; } .box img:hover{ transform: rotateY(60deg); } </style> </head> <body> <div class="box"> <img src="./images/1.jpg" alt=""> </div> </body> </html>
左手握住旋转轴,木质指向正值方向,其他四个手指弯曲方向为旋转正值方向
rotate(x,y,z,角度度数):涌来设置自定义旋转轴的位置及旋转的角度
x,y,z取值为0-1之间的数字
设置元素的子元素是位于3D空间中还是平面中
transform-style
flat:自己处于平面中
preserve-3d:子级处于3D空间中
1)(直接)父元素添加transform-style:preserve-3d;
2)子级定位
3)调整盒子的位置(位移或旋转)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .cube{ width: 200px; height: 200px; margin: 100px auto; transition: all 2s; transform-style: preserve-3d; position: relative; } .cube div{ width: 200px; height: 200px; position: absolute; left: 0; top: 0; } .front{ background-color: orange; transform: translateZ(100px); } .back{ background-color: green; transform: translateZ(-100px); } .cube:hover{ transform: rotateY(90deg); } </style> </head> <body> <div class="cube"> <div class="front">前面</div> <div class="back">后面</div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> img{ width: 200px; height: 200px; } .bigbox{ height: 200px; width: 200px; position: relative; margin: 100px auto; transform-style: preserve-3d; transition: all 2s; } .bigbox div{ width: 200px; height: 200px; position: absolute; left: 0; top:0; } .smallbox1{ transform: translateZ(100px); } .smallbox2{ transform: translateZ(-100px); } .bigbox:hover{ transform: rotateY(90deg); } </style> </head> <body> <div class="bigbox"> <div class="smallbox1"><img src="./images-chifeng/1.jpg" alt=""></div> <div class="smallbox2"><img src="./images-chifeng/2.jpg" alt=""></div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> img{ width: 200px; height: 200px; } .bigbox{ height: 200px; width: 200px; position: relative; margin: 100px auto; transform-style: preserve-3d; transition: all 2s; } .bigbox div{ width: 200px; height: 200px; position: absolute; left: 0; top:0; } .smallbox1{ transform: translateZ(100px); } .smallbox2{ transform: translateZ(-100px); } .smallbox3{ transform: translateX(-100px) rotateY(-90deg); } .smallbox4{ transform: translateZ(100px); transform: rotateY(90deg); } .bigbox:hover{ transform: rotateY(60deg); } </style> </head> <body> <div class="bigbox"> <div class="smallbox1"><img src="./images-chifeng/1.jpg" alt=""></div> <div class="smallbox2"><img src="./images-chifeng/2.jpg" alt=""></div> <div class="smallbox3"><img src="./images-chifeng/3.jpg" alt=""></div> </div> </body> </html>
transform:scale3d(x,y,z);
transform:scaleX();
transform:scaleY();
transform:scaleZ();
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> img{ width: 200px; height: 200px; } .bigbox{ height: 200px; width: 200px; position: relative; margin: 100px auto; transform-style: preserve-3d; transition: all 2s; transform:scale(0.5); } .bigbox div{ width: 200px; height: 200px; position: absolute; left: 0; top:0; } .smallbox1{ transform: translateZ(100px); } .smallbox2{ transform: translateZ(-100px); } .smallbox3{ transform: translateX(-100px) rotateY(-90deg); } .smallbox4{ transform: translateX(100px) rotateY(90deg); } .bigbox:hover{ transform: rotateY(90deg); } </style> </head> <body> <div class="bigbox"> <div class="smallbox1"><img src="./images-chifeng/1.jpg" alt=""></div> <div class="smallbox2"><img src="./images-chifeng/2.jpg" alt=""></div> <div class="smallbox3"><img src="./images-chifeng/3.jpg" alt=""></div> <div class="smallbox4"><img src="./images-chifeng/4.jpg" alt=""></div> </div> </body> </html>
过度:实现两个状态间的变化过程
动画:实现多个状态间的变化过程,动画过程可控(重复播放、最终画面、是否暂停)
方法一:
@keyframes 动画名称{
from {}
to{}
}
方法二:
@keyframes 动画名称{
0%{}
10%{}
......
100%{}
}
animation:动画名称 动画花费时长;
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ width: 200px; height: 200px; background-color: pink; animation: change 1s; } @keyframes change { from{ width: 200px; } to{width: 800px;} } </style> </head> <body> <div class="box"></div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ width: 200px; height: 200px; background-color: pink; animation: change 1s; } @keyframes change { 0% { width: 200px; height: 100px; } 20%{ width: 300px; height: 300px; } 100%{ width: 800; height: 500px; } } </style> </head> <body> <div class="box"></div> </body> </html>
注:百分比可以完成多个状态,百分比表示的意思是动画时长的百分比
animation:动画名称 动画时长 速度曲线 延迟时间 重复次数 动画方向 执行完毕时的状态
提示:
动画名称和动画时长必须复制
取值不分先后顺序
如果有两个时间值,第一个时间表示动画时长,第二个表示延迟时间
速度曲线:linear 匀速 steps() 分步进行
重复播放:写一个数字表示重复几次,如果想一直播放,则需要写infinite
动画方向:alternate是反向
执行完毕:forwards是停在结束状态
拆分属性
animation-timing-function
速度曲线
steps(数字):逐帧动画
animation:
动画1,
动画2,
动画n;
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> *{ list-style: none; margin: 0; padding: 0; } img{ display: block; width: 200px; height: 140px; } .box{ width: 600px; height: 110px; border: 5px solid #000; margin: 100px auto; overflow: hidden; } .box ul{ display: flex; animation: move 5s infinite linear; } @keyframes move { 0%{ transform: translate(0); } 100%{ transform: translate(-1000px); } } .box:hover ul{ animation-play-state: paused; } </style> </head> <body> <div class="box"> <ul> <li><img src="./images-chifeng/1.jpg" alt=""></li> <li><img src="./images-chifeng/1.jpg" alt=""></li> <li><img src="./images-chifeng/1.jpg" alt=""></li> <li><img src="./images-chifeng/1.jpg" alt=""></li> <li><img src="./images-chifeng/1.jpg" alt=""></li> <!-- 填补空白 --> <li><img src="./images-chifeng/1.jpg" alt=""></li> <li><img src="./images-chifeng/1.jpg" alt=""></li> <li><img src="./images-chifeng/1.jpg" alt=""></li> </ul> </div> </body> </html>
rem单位,是相对单位
rem单位是相对于HTML标签的字号计算结果
1rem=1HTML字号大小(需要先给html加字号)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> *{ margin: 0; padding: 0; } html{ font-size: 30px; } .box{ width: 5rem; height: 3rem; background-color: pink; } </style> </head> <body> <div class="box"></div> </body> </html>
媒体查询
媒体查询能够检查视口的宽度,执行差异化的CSS样式
当某个条件成立,执行对应的CSS
属性
@media(媒体特性){
选择器{
CSS属性
}
}
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> @media (width:375px){ body{ background-color: green; } } </style> </head> <body> </body> </html>
`<body>
<script src="./js/flexible.js"></script>
</body>`
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ width: 5rem; height: 3rem; background-color: pink; } </style> </head> <body> <div class="box"></div> <script src="./js/flexible.js"></script> </body> </html>
rem单位尺寸=px单位数值/基准根字号
less是一个CSS预处理器,Less文件后缀是.less。扩充了CSS语言,使CSS具备一定的逻辑性、计算能力
注意:浏览器不识别less代码,目前阶段网页要引入对应的CSS文件
语法://注释内容
快捷键:ctrl+/
语法:/注释内容/
快捷键:Shift+Alt+A
运算:
加减乘除直接写计算表达式
除法需要添加小括号或。
`.box{
width: 100 + 20px;
width: 300 - 15px;
height: (100 / 5)px;
height: 20 * 5px;
}`
注:如果有多个单位,则以第一个出现的单位为准
.父级选择器{
.子级选择器{
}
}
`.father{
color: red;
.son{
width: 200px;
a{
color: pink;
}
}
}`
`.father{
color: red;
.son{
width: 200px;
a{
color: pink;
&:hover{
color: red;
}
}
}
}`
用&不会生成后代选择器
概念:容器,存储数据
作用:存储数据,方便使用和修改
语法:
定义变量:@变量名:数据;
使用变量:CSS属性:@变量名;
//定义变量 @myColor:pink; //使用变量 div{ color: @myColor; }
作用:导入less公共样式文件
语法:导入:@import "文件路径";
提示:如果是less文件可以省略后缀
@import './base.less'
写法 :在less文件的第一行添加//out:存储URL
提示:文件夹名称后面添加/
//out: ./index.css
写法:在less文件第一行添加://out:false
左侧并没有文件生成
相对单位
相对视口的尺寸计算结果
vw:viewport width
1vw = 1 / 100视口宽度
vh:viewport height
1vh = 1 / 100视口高度
vw
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> *{ margin: 0; padding: 0; } .box{ width: 50vw; height: 30vw; background-color: pink; } </style> </head> <body> <div class="box"></div> </body> </html>
vh
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> *{ margin: 0; padding: 0; } .box{ width: 50vh; height: 30vh; background-color: pink; } </style> </head> <body> <div class="box"></div> </body> </html>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。