无法识别的< section>的解决方法旧版浏览器中的标记 [英] Workaround for unrecognized <section> tags in older browsers

查看:162
本文介绍了无法识别的< section>的解决方法旧版浏览器中的标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一对嵌套的部分标签来设置我的内容的宽度,但是浏览器(或浏览器的版本)无法识别标签时出现问题:他们只是允许内容填满整个内容父容器的宽度。

I have a pair of nested section tags to set the width of my content, but am having problems with browsers (or versions of browsers) that don't recognize the tag: they're just allowing the content to fill the entire width of the parent container.

我的代码看起来基本上是这样的:

My code looks essentially like this:

<body>
    <section style="min-width:800px">
        <section style="width:500px">
            <p>Bunch of Text Here That Forms The Content</p>
        </section>
    </section>
</body>

现在在浏览器中无法识别< section >标签,内部< section >中的内容就像标签不存在一样,内容只是填充页面的宽度。我知道我能做些什么吗?

Now in browsers that don't recognize the <section> tag, the content in the inner <section> behaves as if the tag does not exist, and the content simply fills the width of the page. Any idea what I can do about it?

推荐答案

如果你不介意你的网站的设计和布局取决于旧版浏览器的JavaScript (主要是IE版本6-8),您可以使用 HTML5 JavaScript垫片进行IE浏览 Modernizr

If you don't mind your site's design and layout depending on JavaScript for older browsers (mainly IE versions 6-8), you can use the HTML5 JavaScript shim for IE or Modernizr:

<head>
    <meta charset="utf-8" />
    <title>Stack Overflow Rocks!</title>

    <link rel="stylesheet" href="/path/to/file.css" media="all" />

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

要使用此脚本,必须将其包含在元素之前(即在< head> )但是如果它出现在任何CSS之前或之后都无关紧要。但是,为了提高性能,最好在此脚本之前包含任何CSS。

To use this script, it must be included before the element (i.e. in the <head>) but doesn't matter if it appears before or after any CSS. However, for the sake of performance, it's preferable to include any CSS before this script.

不依赖于JavaScript的聪明且有点创造性的方法是在语义HTML5元素中插入IE / Win 6-8可以理解的元素(例如普通的旧< div> ):

A clever and somewhat creative approach that doesn't rely on JavaScript is to insert an element that IE/Win 6-8 understands, (such as a plain old <div>) inside of the semantic HTML5 elements:

<aside>
    <div id="sidebar">
        <!-- Business as Usual Here -->
        ...
    </div>
</aside>

然后,您可以使用ID(对于旧浏览器)或HTML5元素(对于现代浏览器):

You can then apply your CSS using either the ID (for older browsers) or the HTML5 element (for modern browsers):

aside,
#sidebar {
    ...
}

虽然这种方法为每个HTML5元素添加了一组额外的标签— 并且可以说是纯粹的原生HTML5方法—它不依赖于JavaScript和您的网站布局在启用或未启用JavaScript的情况下看起来相同

While this approach adds an extra set of tags for each HTML5 element — and arguably isn't a pure as the native HTML5 method — it doesn't depend on JavaScript and your site's layout can look the same with or without JavaScript enabled.

有关HTML5元素和IE / Win的进一步阅读,请参阅故事HTML5 Shiv

这篇关于无法识别的&lt; section&gt;的解决方法旧版浏览器中的标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆