Css3计算函数:mod运算符出现问题



我正在使用:宽度:calc(100%mod 320)
但是它总是返回父元素的整个宽度。语法似乎没有什么问题——它看起来像是一个支持问题。在chrome 37和firefox 32.0上测试。这是一把小提琴

<div class="mod">test2</div><!-- it should be 100px -->
.mod{
    width:calc(300px mod 200);
}

1)看起来只有IE支持mod运算符,而且它确实像您想象的那样起作用。

2) 您需要在模(如C链路所述)的单元上添加px

3) 正如@Harry所提到的,当前规范已经从计算函数中删除了mod运算符

FIDDLE-(在Internet explorer上尝试)

示例标记-

<div class="container">
    <div class="no">no calc</div>
    <div class="simple">simple</div>
    <div class="mod1">mod1</div>
    <div class="mod2">mod2</div>
    <div class="mod3">mod3</div>
    <div class="mod4">mod4</div>
</div>

CSS(测试用例)

.container {
    width: 450px;
    border: 1px solid black;
}
.no {
   background:aqua; 
}
.simple {
    width:calc(100% - 100px);
    background:green;
}
.mod1 {
    width:calc(100% mod 200px); /* = 450 % 200 = 50px */
    background:red;
}
.mod2 {
    width:calc(100% mod 300px); /* = 450 % 300 = 150px */
    background:brown;
}
.mod3 {
    width:calc(100% mod 50px); /* = 450 % 50 = 0 */
    background:orange;
}
.mod4 {
    width:calc(50% mod 100px); /* = 225 % 100 = 25px */
    background:yellow;
}

25%mod 2(25%的余数除以2)

对你有用的链接,学习使用这个功能如何在CSS3中使用Calc函数

CSS

.mod{
    width: calc(300px - ((300px / 200) * 200));
    background:red;
}

DEMO

最新更新