2014-05-12 23 views
0

我正在開發一個使用CakePHP 2的應用程序,並且已經遇到了default.ctp模板文件中的一個問題。我在網上搜尋,無法找到適合我的答案。我無法找到一種爲IE添加條件CSS文件的方法。CakePHP 2 IE有條件的CSS在default.ctp

我做我的正常的CSS

echo $this->Html->css(array('screen', 'print')); 

echo $this->fetch('css'); 

下面這工作正常,併產生以下HTML。

<link rel="stylesheet" type="text/css" href="/css/screen.css" /> 
<link rel="stylesheet" type="text/css" href="/css/print.css" /> 

我需要什麼才能夠添加到上面CSS是下面的條件包括

<!--[if IE]> <link rel="stylesheet" type="/text/css" href="/css/ie.css" /> <![endif]--> 

我不能看到如何包括ie.css到的css文件前陣的取。

我希望在解決這個問題上有任何幫助。

問候

rickl

回答

1

您可以使用條件CSS包括

以下內容添加到您的佈局

<?php if ($ieCond = $this->fetch('ie')): ?> 
<!--[if IE]><?php echo $ieCond; ?><![endif]--> 
<?php endif; ?> 

以下內容添加到您的查看

<?php $this->Html->css('ie', array('block' => 'ie')); ?> 

來源:CakePHP Api

測試在IE11和FF→我的作品。

2

僅有IE條件塊即間添加的CSS

<!--[if IE]> 
<?php $this->Html->css(array('ie'); ?> 
<![endif]-->