javascript - 当容器有右滚动条时,Flex 元素宽度不能在 IE11 中工作

标签 javascript html css flexbox internet-explorer-11

举个例子

.FlexContainer {
	background: hsla(0,0%,0%,.1);
	display: flex;
	flex-direction: column;
	max-height: 220px;
	margin: 10px;
	padding: 20px;
	width: 300px;
	overflow-y: auto;
}

.FlexItem {
	background: hsla(0,0%,0%,.1);
	width: 80%;
	margin: 2px;
	padding: 6px;
	word-break: break-all;
	white-space: normal;
	cursor: pointer;
}

.FlexItem:hover{
	background-color: red;
}
<html>
<head>
<title>demo</title>
</head>
<body>
<div class="FlexContainer">
    <div class="FlexItem">
        The contents is short in IE11.
    </div>
    <div class="FlexItem">
        The contents is long - inside of this box are overflowing their container in IE11.
    </div>
	<div class="FlexItem">
        The contents inside of this box are overflowing their container in IE11.
    </div>
	<div class="FlexItem">
        The contents inside of this box are overflowing their container in IE11.
    </div>
	<div class="FlexItem">
        The contents inside of this box are overflowing their container in IE11.
    </div>
	<div class="FlexItem">
        The contents inside of this box are overflowing their container in IE11.
    </div>
	<div class="FlexItem">
        The contents inside of this box are overflowing their container in IE11.
    </div>
	<div class="FlexItem">
        The contents inside of this box are overflowing their container in IE11.
    </div>
	<div class="FlexItem">
        The contents inside of this box are overflowing their container in IE11.
    </div>
	<div class="FlexItem">
        The contents inside of this box are overflowing their container in IE11.
    </div>
</div>
</body>
</html>

在 chrome 中它可以很好地工作 chrome work well

但在 IE11 中这不是我所期望的。 IE11 work not expected

此问题仅在容器高度小于 fex 元素并设置 overflow-y:auto/scroll 时发生。

谁能帮我找出问题的原因?

感谢您的帮助。

最佳答案

Internet Explorer 需要您指定子项的 flex 值。 尝试将属性 flex: 1 0 auto; 添加到 FlexItem

关于javascript - 当容器有右滚动条时,Flex 元素宽度不能在 IE11 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54822624/

相关文章:

CSS - 链接的 div 影响 child

javascript - 调用函数时遇到问题

Javascript:我怎样才能 'announce' 一个函数而不调用它?

javascript - 从 ajax 响应返回的选择器上的事件委托(delegate)

html - 最后一个 child 似乎没有工作

javascript - 椭圆化水平列表

javascript - GetElementsByName 带有类似名称的数组

javascript - 如何将 JavaScript 项添加到 Visual Studio 解决方案

html - 样式化 ul 标签和 li 标签而不影响其他 ul 和 li

html - 仅在移动设备上显示 Bootstrap 导航栏。