请考虑以下代码片段:

.parent {
  display: flex;
  flex-direction: column;
  width: 400px;
  border: 1px solid red;
  align-items: center;
}
.child {
  border: 1px solid blue;
}
<div class="parent">
  <div class="child">
    Lorem Ipsum is simply dummy text of the printing and typesetting industry
  </div>
  <div class="child">
    Lorem Ipsum is simply dummy text of the printing and typesetting industry
  </div>
</div>

在Chrome中,文本按预期换行:

enter image description here

但是,在IE11,the text is not wrapping:

enter image description here

这是IE中的已知错误吗?(如有,敬请指点)

是否有已知的解决方法?


This similar question没有明确的答案和官方的指标.

推荐答案

将此代码添加到您的代码中:

.child { width: 100%; }

我们知道一个块级的子对象应该占据父对象的整个宽度.

Chrome理解这一点.

无论出于什么原因,IE11都想要一个明确的请求.

使用flex-basis: 100%flex: 1也可以.

.parent {
  display: flex;
  flex-direction: column;
  width: 400px;
  border: 1px solid red;
  align-items: center;
}
.child {
  border: 1px solid blue;
  width: calc(100% - 2px);       /* NEW; used calc to adjust for parent borders */
}
<div class="parent">
  <div class="child">
    Lorem Ipsum is simply dummy text of the printing and typesetting industry
  </div>
  <div class="child">
    Lorem Ipsum is simply dummy text of the printing and typesetting industry
  </div>
</div>

注意:有时需要对HTML struct 的各个级别进行排序,以确定哪个容器获得width: 100%.CSS wrap text not working in IE

Css相关问答推荐

在ReactJS中使用动画在栅格上添加柱

如何使用在另一个层定义块中定义的sass层作用域变量

如何在点击时停止动画并将其返回到第一帧?

如何在css中创建文件div效果

无法在 React 组件 (TypeScript) 中应用 Tailwind CSS 类

如何取消 CSS 伪类中的属性设置?

为什么 :focus 会覆盖 :focus-visible ?

解释 "document.styleSheets[0].cssRules[0].style;"

我如何使用 CSS 在我的应用程序中每隔 3 位用逗号分隔数字?

在 CSS 中,如何用破折号填充段落中每一行的空白区域?

应用填充时边框无法正常工作

Tailwind css 和 Next.js 导航组件 z-index 不工作

CSS 仅过渡背景 colored颜色

使用 node-sass 在压缩文件末尾添加 min.css 文件扩展名

如何使单选按钮看起来像切换按钮

iPhone X / 8 / 8 Plus CSS 媒体查询

根据背景 colored颜色 反转 CSS 字体 colored颜色

CSS3 box-shadow:inset 可以只做一侧或两侧吗?喜欢边界顶部?

将 Fixed div 设置为父容器的 100% 宽度

将 -moz-available 和 -webkit-fill-available 放在一个宽度中(CSS 属性)