无法在 IE 中设置 HTML5 元素的样式(尽管有 shiv 和 display:block)

发布于 2025-01-07 19:25:42 字数 215 浏览 1 评论 0原文

我似乎无法弄清楚缺少什么。所有受影响的元素都有 display:block

header 元素的示例样式:

header
{
    width: 923px;
    height: 55px;
    background: #395168;
    margin-top: 25px;
}

I can't seem to work out what's missing. All the affected elements have display:block

Example style for the header element:

header
{
    width: 923px;
    height: 55px;
    background: #395168;
    margin-top: 25px;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

独留℉清风醉 2025-01-14 19:25:42

IE 6-8 不知道 header 标记,因此无法对其应用样式。要使 IE 理解此标记,请在 head 部分添加以下脚本。

<script language='javascript'>
document.createElement('header');
</script>

这可以解决你的问题。

IE 6-8 doesn't know about the header tag, so that the styles can't be applied to it. To make IE to understand this tag, add the below script in your head section.

<script language='javascript'>
document.createElement('header');
</script>

This would solve your problem.

一身骄傲 2025-01-14 19:25:42

解决了问题。我所做的是将脚本链接放在样式表链接下,突然 IE 6-8 应用了我的样式。

<link rel="stylesheet" href="styles/style.css" type="text/css">

<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

非常感谢您尝试帮助我:)

Solved the issue. What i did was that i put the script-link under the stylesheet link and suddenly IE 6-8 applied my styles.

<link rel="stylesheet" href="styles/style.css" type="text/css">

<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

Thank you so much for trying to help me :)

墨小墨 2025-01-14 19:25:42

也许只是尝试给它上课?

Maybe just try giving it a class?

心凉 2025-01-14 19:25:42

IE 目前不允许将样式应用于这些元素。我解决这个问题的方法是将它们包装在另一个 div 中:

<div class="header">
    <header>
    </header>
</div>

这显然不是很好,但它击败了任何依赖 JS 的解决方案,因为它不会在禁用 JS 的情况下奇怪地显示。

IE doesn't currently allow styling to be applied to these elements. The way I solve it is by wrapping them in another div:

<div class="header">
    <header>
    </header>
</div>

This isn't great obviously, but it beats any solution that relies on JS as it won't display strangely with JS disabled.

柏拉图鍀咏恒 2025-01-14 19:25:42

今天我自己也遇到了这个问题,升级到最新的 html5shiv 代码(现已移至 Github:https://github.com/aFarkas /html5shiv),将样式表移到脚本链接上方,所有元素都设置了 display:block 但仍然没有成功设置它们的样式...

我意识到我的标记中没有 doctype 声明 - 添加:

<!DOCTYPE html>

解决了问题,所有款式现在正确应用 - 如此完整的解决方案:

<!DOCTYPE html>
<html>
    <head>
        <link href="/css/styles.css" rel="stylesheet" type="text/css">
        <script src="/js/html5shiv.min.js"></script>
    </head>
    <body>
        <!-- html 5 markup -->
    </body>
</html>

Had this problem myself today, upgraded to latest html5shiv code (now moved to Github here: https://github.com/aFarkas/html5shiv), moved the stylesheet above the script link, all elements had display:block set but still no luck styling them...

The I realised I had no doctype declaration in my markup - adding:

<!DOCTYPE html>

solved the problem, all styles now applying correctly - so complete solution:

<!DOCTYPE html>
<html>
    <head>
        <link href="/css/styles.css" rel="stylesheet" type="text/css">
        <script src="/js/html5shiv.min.js"></script>
    </head>
    <body>
        <!-- html 5 markup -->
    </body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文