width:100vh与min-height:calc(100vh + 51px)

本文介绍了视窗单位vh和vw的概念及其在网页布局中的应用,并详细解析了CSS3中新增的calc功能,展示了如何通过表达式动态计算元素尺寸。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

vh:相对于视窗的高度,那么vw:则是相对于视窗的高度。

“视区”所指为浏览器内部的可视区域大小,即window.innerWidth/window.innerHeight大小,不包含任务栏标题栏以及底部工具栏的浏览器区域大小。

详细vh的用法,大家可以参考http://www.zhangxinxu.com/wordpress/2012/09/new-viewport-relative-units-vw-vh-vm-vmin/  

calc是英文单词calculate(计算)的缩写,是CSS3的一个新增的功能,用来指定元素的长度。比如说,你可以使用calc()给元素的border、margin、pading、font-size和width等属性设置动态值。为何说是动态值呢?因为我们使用的表达式来得到的值。不过calc()最大的好处就是用在流体布局上,可以通过calc()计算得到元素的宽度。

 

转载于:https://www.cnblogs.com/ysx215/p/7002989.html

<div class="single_device_container_flex" :class="[ layout.length == 1 ? 'one' : '', layout.length == 2 ? 'two' : '', layout.length == 3 ? 'three' : '', ]" > <div class="single_device_container_video" v-for="(item, index) in layout" :key="item.i" > </div> </div> 如果 layout.length == 3的时候怎么让布局按左右,然后右边两个各一半,左边一整个,父盒子布局如下,怎么修改.single_device { width: 100vw; height: 100vh; background: rgba(0, 0, 0, 0.2); position: fixed; top: 0; left: 0; z-index: 1004; display: flex; flex-direction: column; justify-content: center; align-items: center; .close { width: 60px; height: 60px; background: url("~@/assets/images/map/close.png"); background-size: 100% 100%; margin: 0 auto; cursor: pointer; } &_bg { width: 45%; height: 60%; background: url("~@/assets/images/map/dialog_bg.png") no-repeat; background-size: 100% 100%; padding: 20px; } &_container { width: 100%; height: 100%; background-color: #daeafb; border-radius: 32px; padding: 15px; display: flex; flex-direction: column; // justify-content: space-between; &_flex { flex: 1 1 auto; width: 100%; height: 100%; display: flex; align-items: center; .content { width: 100%; height: 100%; border-radius: 4px; position: relative; aspect-ratio: 16/9; .content_bf { position: absolute; right: 4px; top: 44%; z-index: 9999; img { width: 40px; height: 40px; vertical-align: middle; cursor: pointer; } } } &_video { flex: 1 1 auto; min-height: 0; // 防止溢出 margin-bottom: 10px; // 其它样式不变 .content { width: 100%; max-width: 100%; max-height: 100%; border-radius: 4px; aspect-ratio: 16/9; } } } .one { min-width: 50%; max-width: 100%; height: calc(100% - 10px); .content_bf > img { width: 60px; height: 60px; } .one_video { margin: 0 auto; height: 100%; } } .two { width: 50%; display: flex; justify-content: space-between; height: calc(100% - 10px); .one_video, .two_video { height: 90%; } } .three { width: calc(100% - 10px); display: grid; grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr; gap: 10px; height: calc(100% - 210px); .one_video, .two_video, .three_video { height: 100%; } .one_video { grid-column: 1; grid-row: 1 / span 2; display: flex; align-items: center; justify-content: center; } .two_video { grid-column: 2; grid-row: 1; display: flex; align-items: center; justify-content: center; } .three_video { grid-column: 2; grid-row: 2; display: flex; align-items: center; justify-content: center; } } &_content { flex: 0 0 auto; padding-bottom: 20px; min-height: 110px; .title { font-family: "MyCustomFont"; font-size: 20px; color: #5f93d2; display: flex; margin: 10px 0; align-items: center; .circle { width: 10px; height: 10px; margin-right: 4px; border-radius: 50%; background: #5f93d2; } } &_top { display: flex; justify-content: space-between; &_left { width: 75%; .content { width: 100%; display: flex; margin-top: 5px; .is_online { width: 70px; display: flex; align-items: center; margin-right: 10px; .circle { width: 10px; height: 10px; margin-right: 4px; border-radius: 50%; background: #80c28c; } .value { font-family: Heiti SC; font-size: 20px; font-weight: 300; color: #80c28c; } } .device_info, .up_time, .quantity_of_electricity { display: flex; align-items: center; font-family: Heiti SC; font-weight: 300; font-size: 20px; margin-right: 10px; color: #5f93d2; // .value { // // font-size: 15px; // } } } } &_right { width: 25%; .content { width: 100%; margin-top: 5px; display: flex; align-items: center; justify-content: space-between; .lock, .restart, .shutdown { width: 50px; height: 30px; border-radius: 5px; display: flex; justify-content: center; align-items: center; box-sizing: border-box; margin-right: 10px; font-size: 14px; cursor: pointer; } .lock { border: 1px solid #ff9e47; color: #ff9e47; cursor: pointer; } .restart { border: 1px solid #5f93d2; color: #5f93d2; cursor: pointer; } .shutdown { border: 1px solid #5f93d2; color: #5f93d2; cursor: pointer; } } } } &_bottom { .content { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; .number_of_broadcasts { width: 30%; margin-right: 10px; display: flex; align-items: center; .label { width: 90px; font-family: Heiti SC; font-size: 15px; font-weight: 300; display: flex; align-items: center; color: #5f93d2; } } .sending { width: 50px; height: 30px; border-radius: 5px; display: flex; justify-content: center; align-items: center; background: #5f93d2; color: #fff; font-size: 14px; cursor: pointer; } } } } } }
最新发布
06-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值