定义:
calc() 函数用于动态计算长度值。
用法 :
特别注意:
1、运算符前后都需要保留一个1空格,例如:width: calc(100% - 10px);
2、任何长度值都可以使用calc()函数进行计算;
3、calc()函数支持 “+”, “-”, “*”, “/” 运算;
3、calc()函数使用标准的数学运算优先级规则;
实例:
1、处理布局中的定位:- 1 .parent{
- 2 height: 300px;
- 3 width: 100%;
- 4 position: relative;
- 5 background-color: #ccc;
- 6 }
- 7 .children {
- 8 width: 50px;
- 9 height: 50px;
- 10 top: calc(50% - 25px);
- 11 left: calc(50% - 25px);
- 12 position: absolute;
- 13 border: 1px solid red;
- 14 }
复制代码 效果展示:
children元素定位的位置页可以由calc的值进行控制,children元素水平垂直居中

参考:https://blog.csdn.net/bigpatten/article/details/107142371
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |