another newbie question :/ where can I add conditional css ? im working on my first SS website, using higherground theme, and it doesn't seem to be right in IE..
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Hello, irka!
You can add the conditional css in the templates/Page.ss file, just as it's done in the default Blackcandy theme
thank you :) sorted this problem anyway,,and thanks for the theme :)
Another, "better"(?) but slightly more complicated method I've found for doing this is to add your CSS via the Requirements::css static method in your page controller - you can achieve the same results as conditional statements like so:
function init() {
parent::init();
Requirements::css( project() . "/css/default.css");
if($pos = strpos( $_SERVER[ 'HTTP_USER_AGENT' ], 'MSIE' ) ) {
Requirements::css( project() . "/css/ie.css");
$version = substr( $_SERVER[ 'HTTP_USER_AGENT' ], $pos + 5, 3 );
if( $version < 7 ) {
Requirements::css( project() . "/css/ie6.css");
}
if( $version < 6 ) {
Requirements::css( project() . "/css/ie5.css");
}
}
}
}
(You would add this to the Page_Controller class in your mysite/Page.php file)
The advantage here is that you can create page types that extend the Page class and they will automatically pick up the inherited CSS files. You could then then add additional, custom stylesheets for a specific page type if you wanted.
Handy method. You should add this to the CSS page in the documentation - http://doc.silverstripe.com/doku.php?id=css for other peoples reference
You can also place this in the Page_Controller function init() and lose the hard coded entries in Page.ss.
Requirements::insertHeadTags("<!--[if IE 6]><style type='text/css'>@import url(themes/" . SSViewer::current_theme() . "/css/ie6.css);</style><![endif]-->");
Requirements::insertHeadTags("<!--[if IE 7]><style type='text/css'>@import url(themes/" . SSViewer::current_theme() . "/css/ie7.css);</style><![endif]-->");
Hi there - I found I *had* to add the conditional comments into the Page_Controller function in order to achieve the right hierarchy for the conditional stylesheets, using the BlackCandy theme.
When I included the conditional stylesheets in Page.ss they were included *before* the layout.css file, which then over-wrote some of my fixes.
Hope this helps someone!
Y