如何在这个PHP数组中添加IE8 css hack?

时间:2012-05-30 01:44:34

标签: php css

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

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

我认为=>表明它是以PHP格式完成的。

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

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

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

2 个答案:

答案 0 :(得分:1)

在您的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;'
)

答案 1 :(得分:0)

这个数组很可能(在很好的意义上)注入到你的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]-->

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