如何向这个PHP数组添加一个IE8 css hack


How to add an IE8 css hack to this PHP array?

我需要更新一些预先存在的代码。

css => array(
    'body' => 'overflow-x:hidden;',
    '#wrapper' => 'width:500px;'
)

我假设=>表明它是以PHP格式完成的。

我需要做的是添加一个IE8 css黑客,我试过这个,但无济于事:

css => array(
    'body' => 'overflow-x:hidden;',
    '#wrapper' => 'width:500px;',
    '<!--[if IE 8]>#rightcol' => 'width:200px;<![endif]-->'
)

有人可以帮我解决这个问题吗?

在 HTML 中,将开始正文标记从 <body> 更改为:

<!--[if IE 8]><body class="ie8"><![endif]-->
<!--[if ! IE 8]<!--><body><!--<![endif]-->

然后你可以把.ie8放在任何css选择器之前,使其只在ie8中工作:

css => array(
    'body' => 'overflow-x:hidden;',
    '#wrapper' => 'width:500px;',
    '.ie8 #rightcol' => 'width:200px;'
)

这个数组很可能被注入(在很好的意义上)到你的 css 代码中。如果你知道(通过查看加载的php页面的源代码)是这种情况,那么那里的HTML注释将不适合你,因为它会尝试在css部分编写这些注释,这是无效的。

您需要让它为该IE8条件重写重复的css。因此,您将拥有:

<style type="text/css">
/* this part is filled by your array values */
</style>
<!--[if IE 8]-->
<style type="text/css">
/* this part is the IE8 hack */
</style>
<!--[endif]-->

这将需要并包含另一个样式标签。