使用html5选择器时不应用CSS样式。在渲染CSS方面浏览器有什么变化? [英] CSS styles not applied when using html5 selectors. Has something changed about the browser in terms of rendering CSS?

查看:147
本文介绍了使用html5选择器时不应用CSS样式。在渲染CSS方面浏览器有什么变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近遇到了IE8令人沮丧的情况。这是最奇怪的事情。我以前工作代码停止工作。当我使用诸如 header footer 等HTML5标签时,文章 nav 命名一些,与外部CSS样式表中的对应CSS选择器一起使用。问题是:突然之间的CSS样式不再应用到我的标记。 这就像我没有样式表。

I'm experiencing frustrating situations with IE8 lately. It's the weirdest thing. I had previously working code stop working. It seems to be happening when I'm using HTML5 tags such as header, footer, article and nav to name a few, being used with their counterpart CSS selectors in my external CSS stylesheet. The problem is: all of a sudden the CSS styles are no longer being applied to my markup. It's like I have no stylesheet at all.

我确保我没有收到任何404错误以及没有JavaScript错误。

I've made sure that I'm not getting any 404 errors as well as no JavaScript errors.

我还检查了 DOCTYPE ,以确保我的HTML文档处于标准模式,浏览器状态就是这样。

I've also checked the DOCTYPE to make sure that my HTML document is in standards mode and the browser even states this is the case.

此外,我已经明白,即使浏览器不一定将HTML5标签视为特殊(像大多数现代浏览器一样),它不会篡改他们和他们应该仍然能够在CSS样式表中使用他们各自的选择器。

Also, as I've understood, even though the browser doesn't necessarily view the HTML5 tags as special (like most modern browsers do) it won't tamper with them and they should still be able to be usable in the CSS stylesheet with their respective selectors.

至少这是我从这个Stackoverflow帖子得到的印象:
http://stackoverflow.com/a/7801476/295019

At least that's the impression I got from this other Stackoverflow post: http://stackoverflow.com/a/7801476/295019

总是这样,或者我一直都错了。

Was that always the case or have I been wrong about it the whole time.

我想我应该能够在我的代码中使用HTML5标签,或者如果我的代码失败,什么是使用点。根据我的最佳利益,建立工作在IE8的网站,因为有相当多的人使用它(即我的客户仍然要求他们的网页工作。)

I figured I should be able to use HTML5 tags in my code or what's the point of using it if my code just fails. It is in my best interests to build websites that work on IE8 given that quite a bit of people use it (i.e. my clients still ask for their pages to work on it.)

我还应该在这一点上说明我在Mac上工作,并在使用IE8的VirtualBox上运行的虚拟机版本的Windows 7上测试。也许这与我的问题有关。但是,我已经重新启动了我的机器几次,希望它的工作。我已经确保Flash已安装,并且安装没有损坏(据我所知)。

I should also state at this point that I work on Mac and test on an virtual machine version of Windows 7 running on VirtualBox with IE8. Maybe that has something to do with my problems. However, I have restarted my machine several times in the hope that it will work. I've also made sure that Flash is installed and the installation is not corrupt (to the best of my knowledge.)

有没有人知道发生了什么?或经历类似的问题?

Does anyone have any idea what's going? Or experienced similar problems?

任何帮助将非常感激。

推荐答案

p>不幸的是,您认为IE8适用于HTML5元素的印象不正确。 IE8无法与< section> < header> 的元素正常工作。在页面中使用这些元素将导致IE8的主要问题。

Unfortunately, the impression you've got that IE8 works with HTML5 elements is incorrect. IE8 does not work properly with elements like <section> or <header>. Using these elements in a page will cause major issues for IE8.

好消息是,有一个简单的修复此问题。

The good news is that there is, however, a simple fix for this problem.

修复程序是一个名为 html5Shiv 的脚本。

The fix is a script called html5Shiv.

此脚本使用一些Javascript hacks来使HTML5元素在旧版本的IE中工作。 (即,它只是阻止他们打破页面 - 它显然不添加新的HTML5功能,所以不要期望< canvas> 突然爆发进入生活!)

This script uses a handful of Javascript hacks to make HTML5 elements work in old versions of IE. (that is, it just stops them from breaking the page -- it obviously doesn't add the new HTML5 features, so don't expect <canvas> to suddenly burst into life!)

只需将此脚本添加到页面顶部即可。

Simply add this script to the top of your page and you'll be fine.

另一个选项是名为 Modernizr 的脚本。这包括html5Shiv功能,并且添加了另一层兼容性检查,如果您尝试创建一个现代网站但仍然支持旧的浏览器,这将非常有用。

Another option is a script called Modernizr. This includes the html5Shiv functionality, and also adds another layer of compatibility checking, which can be very beneficial if you're trying to make a modern site but still support old browsers.

希望有所帮助。

这篇关于使用html5选择器时不应用CSS样式。在渲染CSS方面浏览器有什么变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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