CSS子选择器不工作在ie9 [英] CSS child selector doesn't work on ie9

查看:99
本文介绍了CSS子选择器不工作在ie9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的页面:

<body>
<table width="100%">...</table>
<table width="100%">...</table>
<table width="100%">...</table>
<table width="100%">...</table>
</body>

我需要做的是使所有这些表85%的宽度和水平居中的页面。如果页面是单个页面,这将是很容易,但这需要工作在100多个页面,他们唯一的共同点是样式表文件。所以我需要这样做与CSS只。我不能覆盖div里面的表或使用jquery。

what i need to do is making all those tables 85% width and horizontally centered on the page. it would be easy if the page was a single page but this needs to work on 100+ pages and the only thing they have in common is the stylesheet file. so i need to do this with css only. i can't cover the tables inside a div or use jquery.

我试过的是:

body { text-align:center; }
body > table { text-align: left; margin: 0 auto; width: 85%; }

这完全适用于firefox和google chrome,但它似乎不工作ie9但我确定它不会与早期的ie版本)

this works perfectly on firefox and google chrome but it doesn't seem to work on ie9 (didn't tested but i'm sure it won't work with earlier ie versions)

我尝试了很多方法,他们写在类似的问题,但不能能够解决这个问题。

i've tried lots of methods they wrote on similar questions but couldn't be able to solve this.

编辑:

网页的doctype是:

The doctype of the page was:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

我将其更改为:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

它现在工作ie9了!

and it works on ie9 too now!

更新的问题是:是否可以不更改doctype?

The updated question is: is it possible without changing the doctype?

推荐答案

如Yi Jiang所说,你的doctype声明是不正确的。 IE9可能无法弄清楚该怎么做,所以运行回来并隐藏在它的quirks模式shell,它对孩子选择器变得盲目(或者,变成 10 years younger )。

As Yi Jiang says, your doctype declaration isn't correct. IE9 probably can't figure out what to do about that, so runs back and hides in its quirks-mode shell, where it becomes blind to the child selector (or, becomes 10 years younger).

最简单且肯定推荐的方法是更改​​您的doctype声明,标准模式并应用规则:

The easiest and surely-recommended way is to change your doctype declaration in order to get it back to standards mode and apply the rule:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

否则你可以尝试放弃子选择器,并尝试使用任何

Otherwise you can try forgoing the child selector and try to reset styles on the rest of your tables using whatever default styles you'd like:

body { text-align:center; }
body table { text-align: left; margin: 0 auto; width: 85%; }
body * table { /* Styles for other tables */ }

看到 * 选择器看起来不是很友好,所以改变doctype绝对是更好的路径。

But as you see, the * selector there doesn't look very friendly, so changing the doctype is definitely the better path to take.

这篇关于CSS子选择器不工作在ie9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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