热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

多线弯曲在IE11计算宽度不正确?-multiline-flexboxinIE11calculatingwidthsincorrectly?

SeemsIE11doesntcalculateflexitemwidthsproperlyifflex-wrap:wrapisused.看起来IE11没有正确地计算fle

Seems IE11 doesn't calculate flex item widths properly if flex-wrap: wrap is used.

看起来IE11没有正确地计算flex条目宽度,如果使用了flex-wrap: wrap使用。

See http://jsfiddle.net/MartijnR/WRn9r/6/

参见http://jsfiddle.net/MartijnR/WRn9r/6/

The 4 boxes each have flex-basis: 50% so we should get two lines of two boxes each, but in IE11 each box gets one line. When setting the border to 0, it works correctly.

这4个盒子都有弹性基:50%所以我们应该得到两行两个盒子,但是在IE11中每个盒子都有一行。当将边界设置为0时,它可以正常工作。

Any idea if this is a bug, or if there is way to make IE11 behave (and still use borders)?

你知道这是一个bug吗?或者有办法让IE11正常运行吗?

1
2
3
4
section {
    display: -moz-flex;
    display: -webkit-flex;
    display: flex;
    -moz-flex-direction: row;
    -webkit-flex-direction: row;
    flex-direction: row;
    -moz-flex-wrap: wrap;
    -webkit-flex-wrap: wrap;
    flex-wrap: wrap;
    width: 100%;
    box-sizing:border-box;
    margin:0;
}
.box {
    border: 1px solid black;
    background: #ccc;
    display: block;
    -ms-flex: 50%;
    -moz-flex: 50%;
    -webkit-flex: 50%;
    flex: 50%;
    box-sizing: border-box;
    margin:0;
}

P.S. In my project only the last version of popular browsers needs to be supported, thankfully, but IE11 is one of them.

附注:在我的项目中,只需要支持流行浏览器的最后一个版本,谢天谢地,IE11就是其中之一。

4 个解决方案

#1


34  

It looks like a bug where box-sizing is not being taken into account when calculating the size using the flex property. As the border takes up 2px, it is larger than 50% and thus only one fits on a line, so all boxes are stretched to the full width. You can see the same thing happening if you disable the border and add 2px padding instead.

它看起来像一个错误,在使用flex属性计算大小时没有考虑到方框大小。由于边框占了2px,它大于50%,因此只有一个符合线,所以所有的框都被拉伸到全宽。如果禁用边框并添加2px填充,也会发生同样的情况。

You can make it work correctly while keeping the borders by adding max-width: 50% to the .box ruleset. Otherwise you can use a flex value between 33.34% and 49%. This will make the width less than 50% including the border, and as the elements grow to fill available space, they’ll still be 50% of the flex container. Kind of a ugly hack, but it will work unless you add a combined border and padding larger than 50% minus the flex value you set.

您可以通过在.box规则集中添加最大宽度:50%来保持边界正确工作。否则,您可以使用33.34%到49%之间的flex值。这将使宽度小于50%,包括边框,当元素增长到可用空间时,它们仍然是flex容器的50%。这有点难看,但除非你添加一个大于50%的边框和填充,减去你设置的flex值,否则它是可以工作的。

Perhaps a better way than decreasing the percentage value directly is to use calc(). This is supported by all browsers that support the modern Flexbox syntax. You just need to subtract the combined total of the left and right paddings and margins from the percentage value you want to use. As you‘re doing this you don’t really need the box-sizing property so it can be removed. There seems to be another issue in IE where you can’t use calc in the flex shorthand but you can use it in the flex-basis property, which is the one you want.

也许比直接减少百分比值更好的方法是使用calc()。支持现代Flexbox语法的所有浏览器都支持这一功能。您只需要从您想要使用的百分比值中减去左、右围和边距的总和。当你这样做的时候,你并不需要box尺寸属性,这样它就可以被移除。IE中还有一个问题,你不能在flex速记中使用calc,但你可以在flex基础属性中使用calc,这是你想要的。

.box {
    border: 1px solid black;
    /* additional styles removed for clarity */

    /* 
    50% - (border-left-width + border-right-width +
           padding-left + padding-right)
    */
    -webkit-flex-basis: calc(50% - 2px);
    flex-basis: calc(50% - 2px);
}

See the demo: http://jsfiddle.net/dstorey/78q8m/3/

看到演示:http://jsfiddle.net/dstorey/78q8m/3/

#2


9  

I received an workaround on the Microsoft forum from Rob. See http://social.msdn.microsoft.com/Forums/ie/en-US/8145c1e8-6e51-4213-ace2-2cfa43b1c018/ie-11-flexbox-with-flexwrap-wrap-doesnt-seem-to-calculate-widths-correctly-boxsizing-ignored?forum=iewebdevelopment

我在微软论坛上收到了来自Rob的一个解决方案。参见http://social.msdn.microsoft.com/forums/ie/en - us/8145c1e8 6楼- 4213 ace2 - 2 cfa43b1c018/ie - 11 - flexbox flexwrap似乎-包装-不- - -计算-宽度-正确- boxsizing ignored?forum=iewebdevelopment

Setting a min-width and changing to flex:auto makes the boxes behave, maintaining their flexiness.

设置一个最小宽度,并切换到flex:auto使这些箱子的行为,保持它们的灵活性。

See http://jsfiddle.net/MartijnR/WRn9r/23/ and below for a slightly more advanced example with the workaround:

请参阅http://jsfiddle.net/MartijnR/WRn9r/23/及下面的http://jsfiddle.net/MartijnR/WRn9r/23/,了解一个稍微高级一些的解决方案示例:

1
2
3
4
5
section { display: -moz-webkit-flex; display: -webkit-flex; display: flex; -ms-flex-direction: row; -moz-flex-direction: row; -webkit-flex-direction: row; flex-direction: row; -ms-flex-wrap: wrap; -moz-flex-wrap: wrap; -webkit-flex-wrap: wrap; flex-wrap: wrap; width: 100%; box-sizing:border-box; margin:0; } .box { border: 1px solid black; background: #ccc; display: block; box-sizing: border-box; margin:0; -ms-flex: auto; -moz-flex: auto; -webkit-flex: auto; flex: auto; } .fifty { min-width: 50%; } .twentyfive { min-width: 25%; }

#3


6  

Philip Walton has an excellent summary of this bug here: https://github.com/philipwalton/flexbugs#7-flex-basis-doesnt-account-for-box-sizingborder-box. He proposes two solutions, the easiest of which is to set flex-basis: auto and declare a width instead. (Not max-width or min-width.) This solution has the advantage of not having to adjust your calc() when you change padding or border widths.

Philip Walton在这里对这个错误有一个很好的总结:https://github.com/philipwalton/flexbugs#7-flex-basis-doesnt- accountforsizingborder -box。他提出了两种解决方案,其中最简单的是设置浮动基础:auto和声明宽度。(不是max-width或者min-width)。这种解决方案的优点是,当您更改填充或边框宽度时,不必调整calc()。

#4


5  

This is clearly an IE bug so leave the original [correct] CSS and append a hack that targets IE10+:

这显然是IE的一个bug,所以请保留原始的[正确的]CSS,并添加针对IE10+的黑客攻击:

/* IE10+ flex fix: */
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
    .box {
        flex: 0;
        min-width: 50%;
    }
}

http://jsfiddle.net/stedman/t1y8xp2p/

http://jsfiddle.net/stedman/t1y8xp2p/


推荐阅读
  • 欢乐的票圈重构之旅——RecyclerView的头尾布局增加
    项目重构的Git地址:https:github.comrazerdpFriendCircletreemain-dev项目同步更新的文集:http:www.jianshu.comno ... [详细]
  • 微软头条实习生分享深度学习自学指南
    本文介绍了一位微软头条实习生自学深度学习的经验分享,包括学习资源推荐、重要基础知识的学习要点等。作者强调了学好Python和数学基础的重要性,并提供了一些建议。 ... [详细]
  • EPICS Archiver Appliance存储waveform记录的尝试及资源需求分析
    本文介绍了EPICS Archiver Appliance存储waveform记录的尝试过程,并分析了其所需的资源容量。通过解决错误提示和调整内存大小,成功存储了波形数据。然后,讨论了储存环逐束团信号的意义,以及通过记录多圈的束团信号进行参数分析的可能性。波形数据的存储需求巨大,每天需要近250G,一年需要90T。然而,储存环逐束团信号具有重要意义,可以揭示出每个束团的纵向振荡频率和模式。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 推荐系统遇上深度学习(十七)详解推荐系统中的常用评测指标
    原创:石晓文小小挖掘机2018-06-18笔者是一个痴迷于挖掘数据中的价值的学习人,希望在平日的工作学习中,挖掘数据的价值, ... [详细]
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • 本文介绍了pack布局管理器在Perl/Tk中的使用方法及注意事项。通过调用pack()方法,可以控制部件在显示窗口中的位置和大小。同时,本文还提到了在使用pack布局管理器时,应注意将部件分组以便在水平和垂直方向上进行堆放。此外,还介绍了使用Frame部件或Toplevel部件来组织部件在窗口内的方法。最后,本文强调了在使用pack布局管理器时,应避免在中间切换到grid布局管理器,以免造成混乱。 ... [详细]
  • Introduction(简介)Forbeingapowerfulobject-orientedprogramminglanguage,Cisuseda ... [详细]
  • Imdevelopinganappwhichneedstogetmusicfilebystreamingforplayinglive.我正在开发一个应用程序,需要通过流 ... [详细]
  • MySQL5.6.40在CentOS764下安装过程 ... [详细]
  • 为什么三角形与菜单背景的颜色不同? - Why is the triangle a different colour shade to the menu background?
    Imnotunderstandingastowhythetrianglewhichappearswhenthemousehoversoverthemenuitem, ... [详细]
  • Bro是一款强大的网络安全工具,以及协议识别与统计的工具。Broisapowerfulnetworkanalysisframeworkthatismuchdifferentfro ... [详细]
  • Scrapy 爬取图片
    1.创建Scrapy项目scrapystartprojectCrawlMeiziTuscrapygenspiderMeiziTuSpiderhttps:movie.douban.c ... [详细]
  • 目录爬虫06scrapy框架1.scrapy概述安装2.基本使用3.全栈数据的爬取4.五大核心组件对象5.适当提升scrapy爬取数据的效率6.请求传参爬虫06scrapy框架1. ... [详细]
author-avatar
fvcvb_974
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有