Flexbox可在Internet Explorer中使用,但不能在Chrome中使用

807

我想实现的目标:JSFiddle

<div id="container">
    <div class="box">1</div>
    <div class="box">2</div>
    <div class="box">3</div>
    <div class="box">4</div>
    <div class="box">5</div>
    <div class="box">6</div>
    <div class="box">7</div>
    <div class="box">8</div>
    <div class="box">9</div>
    <div class="box">10</div>
    <div class="box">11</div>
    <div class="box">12</div>
    <div class="box">13</div>
</div>

我想拥有的是,当放置更多的“盒”类时,“盒”类的“ X”数量合适,并使“内容”类更宽。

在Internet Explorer(11)中,您看到“ box”类适合“ content”类并展开,但是在Chrome(41)中,“ box”类似乎浮在“ content”类之上,而在“ content”之外班级宽度。这很烦人,因为如果我要在其旁边放置另一个“内容”类,它将与第一个类重叠。

谁能解释我在做什么错?如果是Chrome故障,有没有建议在没有Flexbox的情况下完成此操作?

解决检查其他主题以获取多个容器!

迈克尔·巴佐斯(Michael P.Bazos)

首先,我建议您不要float: left;混合使用display: flex;考虑display: inline-flex;改为指定

也就是说,恐怕您需要做一些计算,才能找到container元素内所有子项中最大的偏移量(包括边距):

以下代码需要jQuery,并应在DOM准备就绪时运行:

// -----------------------------------------------------------------------------
// Find the biggest offset right among all children, relatively to the container
// -----------------------------------------------------------------------------

var maxOffsetRight = 0,
    currentOffsetRight;

$('#container').children().each(function() {
   currentOffsetRight = $(this).position().left + $(this).outerWidth(true);
    if (currentOffsetRight > maxOffsetRight) {
        maxOffsetRight = currentOffsetRight;
    }
});

// Set the width of the container
var offsetLeft = $('#container').position().left;
$('#container').css('width', maxOffsetRight - offsetLeft);

小提琴

注意:您可能会想到一种算法,该算法寻找最后一个子项的偏移量。这在大多数情况下都可以使用,但可能会失败,而且您可以order在flex项目上设置属性以对其进行重新排序。因此,DOM中的最后一个子对象不一定是具有最大右偏移量的子对象。如果子级具有任意宽度,则在不重新排序元素的情况下也可能会失败。例如,如果同一列中最后一个孩子之前的孩子大于最后一个孩子。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

.NET Core 2 MVC-从Azure Blob存储下载文件可在Google Chrome中使用,但不能在Internet Explorer中使用

CSS动画可以在Chrome和Safari中使用,但不能在Firefox和Internet Explorer中使用

jQuery可在Chrome控制台中使用,但不能在Chrome屏幕中使用

粘性页脚模式可在Chrome中使用,但不能在Firefox中使用

jQuery / Javascript函数可在Chrome中使用,但不能在IE11中使用

WebRTC可在Chrome中使用,但不能在Firefox中使用

简单的AddListener,可在代码笔中使用,但不能在Chrome浏览器中使用

工具提示可在Firefox中使用,但不能在Chrome中使用

parseFloat可在Chrome中使用,但不能在IE或Firefox中使用

JavaScript代码可在Firefox中使用,但不能在Chrome或Edge中使用

javascript setInterval()可在Dreamweaver中使用,但不能在Chrome中使用

CSS动画可在Chrome中使用,但不能在FireFox中使用

JavaScript登录按钮可在IE中使用,但不能在Chrome或Firefox中使用

jQuery代码可在chrome和IE中使用,但不能在Firefox中使用

正则表达式可在Chrome上使用,但不能在Safari中使用

jwplayer getDuration可在chrome控制台中使用,但不能在具有IJavaScriptExecutor的C#中使用

Javascript代码可在Chrome中使用,但不能在其他浏览器中使用

jQuery ajax可在Chrome和Safari中使用,但不能在IE8和Firefox中使用

xpath可在chrome控制台中使用,但不能在量角器脚本中使用

排序/排序文本和数字可在Firefox和Chrome中使用,但不能在Safari中使用

Python Match Regex可在测试器中使用,但不能在consol中使用

javascript代码可在jsfiddle中使用,但不能在浏览器中使用

Javascript代码可在JSFiddle中使用,但不能在浏览器中使用

下载Excel可在Postman中使用,但不能在Javascript中使用

SQL查询可在DB客户端中使用,但不能在Laravel应用中使用

Http POST可在邮递员中使用,但不能在Flutter中使用

XPath可在浏览器中使用,但不能在简单的HTML DOM中使用

按钮样式可在Android 5中使用,但不能在Android 4中使用

XPath查询可在XPath测试器中使用,但不能在VB.NET中使用