calc 计算属性
1. 官方定义
2. 解释
3. 语法
解释:demo 的宽度 = 父元素总体宽度 - 80px 。
4. 兼容性
IE | Edge | Firefox | Chrome | Safari | Opera | ios | android |
---|---|---|---|---|---|---|---|
11 | 12+ | 16+ | 19+ | 6+ | 15+ | 6.1+ | 81 |
5. 实例
- 让 demo 的宽度比父级宽度小 200px。
.out-Box{
border:px solid #ccc;
width: px;
height: px;
}
.demo{
border:px solid #ccc;
height:px;
width: calc( - px);
}
@H_502_7@@H_502_78@
效果图:
<!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>
.out-Box{
border:px solid #ccc;
width: px;
height: px;
}
.demo{
border:px solid #ccc;
height:px;
width: calc( - px) ;
}
</style>
</head>
<body>
<div class="out-Box">
<div class="demo">
网:计算函数学习
</div>
</div>
</body>
</html>
@H_502_7@@H_502_78@
- 使 demo 的宽度、高度为父元素的 1/3。
.out-Box{
border:px solid #ccc;
width: px;
height: px;
}
.demo{
border:px solid #ccc;
height: calc( /);
width: calc( /);
}
@H_502_7@@H_502_78@
效果图:
<!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>
.out-Box{
border:px solid #ccc;
width: px;
height: px;
}
.demo{
border:px solid #ccc;
height: calc( /) ;
width: calc( /) ;
}
</style>
</head>
<body>
<div class="out-Box">
<div class="demo">
网:计算函数学习
</div>
</div>
</body>
</html>
@H_502_7@@H_502_78@
- 使 demo 的宽度、高度为父元素的 (100% + 200px) /3。
.out-Box{
border:px solid #ccc;
width: px;
height: px;
}
.demo{
border:px solid #ccc;
height: calc( ( + px) /);
width: calc( ( + px) /);
}
@H_502_7@@H_502_78@
效果图:
<!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>
.out-Box{
border:px solid #ccc;
width: px;
height: px;
}
.demo{
border:px solid #ccc;
height: calc( ( + px) /) ;
width: calc( ( + px) /) ;
}
</style>
</head>
<body>
<div class="out-Box">
<div class="demo">
网:计算函数学习
</div>
</div>
</body>
</html>
@H_502_7@@H_502_78@
6. 经验分享
我们可以写成 :