简体   繁体   English

Internet Explorer CSS:Joomla自定义模板

[英]Internet explorer css: Joomla Custom template

I am trying to add an internet explorer only css file called ie.css. 我试图添加一个名为ie.css的仅Internet Explorer的CSS文件。

I have built a simple custom joomla template, it is working fine in every browser except....usual culprit IE! 我已经构建了一个简单的自定义joomla模板,除了....通常的罪魁祸首IE,它在所有浏览器中都可以正常工作!

I have added ie.css to the css folder and i am struggling to get the file to only be read from IE. 我已经将ie.css添加到css文件夹中,我正在努力使该文件只能从IE读取。 This is my .php file: 这是我的.php文件:

 <?php $doc = JFactory::getDocument(); $doc->addStyleSheet('templates/' . $this->template . '/css/main.css'); $doc->addStyleSheet('templates/' . $this->template . '/css/header.css'); $doc->addStyleSheet('templates/' . $this->template . '/css/footer.css'); $doc->addStyleSheet('templates/' . $this->template . '/css/container.css'); $stylelink = '<!--[if lte IE 9]>' ."\\n"; $stylelink .= '<link rel="stylesheet" href="/css/ie.css" />' ."\\n"; $stylelink .= '<![endif]-->' ."\\n"; $document = JFactory::getDocument(); $document->addCustomTag($stylelink); $doc->addScript('/templates/' . $this->template . '/java/java.js', 'text/javascript'); ?> <!DOCTYPE html> <html> <head> <jdoc:include type="head" /> <!--[if gte IE 9]> <style type="text/css"> .gradient { filter: none; } </style> <![endif]--> <!--[if IE]> <link rel="stylesheet" type="text/css" href="css/ie.css" /> <![endif]--> </head> <body> <div id="back"> <jdoc:include type="modules" name="background_image" style="none" /></div> <div class="wrapper"> <div id="logo"><jdoc:include type="modules" name="logo" style="none" /></div> <div class="menu"> <jdoc:include type="modules" name="nav-main" style="none" /> </div> <div class="container"> <jdoc:include type="component" /> <div id="home_content_top"> <jdoc:include type="modules" name="content_area_one" style="none" /> </div> <div id="home_discount"> <jdoc:include type="modules" name="content_area_two" style="none" /> </div> <div id="footer"> <jdoc:include type="modules" name="footer" style="none" /> </div> </div> </div> </body> </html> 

Where have i gone wrong? 我哪里出问题了?

You have not defined the base path when trying to call your CSS file, so currently it's trying to find: 尝试调用CSS文件时,您尚未定义基本路径,因此当前正在尝试查找:

www.example.com/css/ie.css

when the actual path is: 当实际路径是:

www.example.com/templates/YOUR_TEMPLATE/css/ie.css

Also, I would not use PHP to render conditional statements. 另外,我不会使用PHP来呈现条件语句。 It's much cleaner to do it without, so remove all of this: 不用它会更清洁,因此删除所有这些:

$stylelink = '<!--[if lte IE 9]>' ."\n";
$stylelink .= '<link rel="stylesheet" href="/css/ie.css" />' ."\n";
$stylelink .= '<![endif]-->' ."\n";
$document = JFactory::getDocument();
$document->addCustomTag($stylelink);

Add add the following inside your <head> tag: 在您的<head>标记内添加以下内容:

<!--[if lte IE 9]>
    <link rel="stylesheet" href="templates/<?php echo $this->template; ?>/css/ie.css" />
<![endif]-->

Just a side note too. 只是一个旁注。 You do not need to call JFactory::getDocument() twice, only once, like you have at the top of your code. 您不需要调用JFactory::getDocument()两次,只需调用一次,就像在代码顶部一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM