【问题标题】:<main> element not working in Internet Explorer 11<main> 元素在 Internet Explorer 11 中不起作用
【发布时间】:2016-06-19 15:03:16
【问题描述】:

我正在尝试使用 CSS 设置 &lt;main&gt; 元素的宽度。只是使用

main {
  width:200px;
}

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

看看这个例子:JSfiddle

IE11 中的结果:

Chrome 中的结果:

【问题讨论】:

    标签: css html internet-explorer internet-explorer-11


    【解决方案1】:

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

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

    进行此调整:

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

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

    display 属性的初始值为inline

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

    10.3.1 Inline, non-replaced elements

    width 属性不适用。

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

    更多细节:

    【讨论】:

    • 谢谢,这行得通!奇怪的是 IE11 不支持这个简单的 HTML5 标签。
    • @JensRenders IE 需要数年时间才能支持所有其他浏览器都支持的新元素、CSS 属性和 API,所以,不,这并不奇怪,在 Edge 中也不会有太大不同。
    • 主要标签是 display: 在 Edge 中默认为 block :)
    猜你喜欢
    • 2016-10-20
    • 2019-08-12
    • 2014-08-22
    • 1970-01-01
    • 1970-01-01
    • 2016-10-15
    • 2015-03-22
    • 2018-01-17
    • 2017-04-02
    相关资源
    最近更新 更多