<main> 元素在 Internet Explorer 11 中不工作

<main> element not working in Internet Explorer 11

我正在尝试使用 CSS 设置 <main> 元素的宽度。仅使用

main {
  width:200px;
}

在除 Internet Explorer 之外的所有浏览器中都可以正常工作(Edge 可以)。

看看这个例子:JSfiddle

IE11 中的结果:

Chrome中的结果:

Internet Explorer (see browser support data) 不支持 HTML5 main 元素。

您需要将 main 定义为块级元素,width 才能正常工作。

进行此项调整:

main {
  display: block;  /* new */
  width: 200px;
}

因为 main 元素不能被 Internet Explorer 识别——这意味着它没有在 IE 的默认样式中定义 sheet – 它使用 CSS 初始值 (per the spec) .

display属性的初始值为inline

width 属性 被内联元素忽略。来自规范:

10.3.1 Inline, non-replaced elements

The width property does not apply.

通过将 main 元素定义为作者样式中的块级元素,width 属性 将起作用。

更多详情: