css – “width:calc(100%/ 3);”在任何IE中都无法正常工作

前端之家收集整理的这篇文章主要介绍了css – “width:calc(100%/ 3);”在任何IE中都无法正常工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个3列布局应该填满整个屏幕所以在我使用的列上:
width: calc(100% / 3);

那么就举个例子说我的屏幕是782px宽:

782 / 3 = 260.66̅

但是我遇到的问题是在Internet Explorer中,它将像素舍入到两位小数(260.67)

260.67 * 3 = 782.01

因此,在某些宽度下,我丢失了1/3的页面,因为它包裹在下面.

这是一个example

function onResize() {
    $('ul').each(function() {
        var H = eval($(this).height() / $(this).children('li').length);
        $(this).children('li').outerHeight(H);
        $(this).children('li').css('line-height',H + 'px');
        $(this).children('li').outerWidth($(this).width());
    });
}

var timer;
$(window).resize( function() {
    timer && clearTimeout(timer);
    timer = setTimeout(onResize,100);
});
onResize();
html {
    height:100%;
}
body {
    background:black;
    margin:0;
    padding:0;
    overflow:hidden;
    height:100%;
}
ul {
    width: calc(100% / 3);
    display: inline-block;
    overflow:hidden;
    margin:0;
    padding:0;
    float:left;
    height:100%;
    list-style: outside none none;
}
ul li {
    background: rgb(230,240,163);
    background: -webkit-gradient(linear,0 0,0 100%,from(rgba(230,163,1)),color-stop(0.5,rgba(210,230,56,color-stop(0.51,rgba(195,216,37,to(rgba(219,67,1)));
    background: -webkit-linear-gradient(rgba(230,1) 0%,1) 50%,1) 51%,rgba(219,1) 100%);
    background: -moz-linear-gradient(rgba(230,1) 100%);
    background: -o-linear-gradient(rgba(230,1) 100%);
    background: linear-gradient(rgba(230,1) 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#e6f0a3',endColorstr='#dbf043',GradientType=0 );
    text-align:center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="ul1">
    <li>Test 1</li>
    <li>Test 2</li>
</ul>
<ul id="ul2">
    <li>Test 3</li>
    <li>Test 4</li>
</ul>
<ul id="ul3">
    <li>Test 5</li>
    <li>Test 6</li>
</ul>

有谁知道解决这个问题的优雅方法

我知道我可以使用宽度:33.33%,但是我内心的一小部分会发出嘶嘶声,知道它并非100%爆炸.

解决方法

尝试宽度:计算(100%* 0.33333);确保浮动舍入错误在警告或宽度方面错误:calc((100%/ 3) – 0.1px);.
原文链接:https://www.f2er.com/css/217351.html

猜你在找的CSS相关文章