简体   繁体   中英

Internet explorer css: Joomla Custom template

I am trying to add an internet explorer only css file called ie.css.

I have built a simple custom joomla template, it is working fine in every browser except....usual culprit IE!

I have added ie.css to the css folder and i am struggling to get the file to only be read from IE. This is my .php file:

 <?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:

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. 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:

<!--[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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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