Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » conditional css

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 4239 Views
  • irka
    Avatar
    Community Member
    9 Posts

    conditional css Link to this post

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

  • Wojtek
    Avatar
    Community Member
    149 Posts

    Re: conditional css Link to this post

    Hello, irka!
    You can add the conditional css in the templates/Page.ss file, just as it's done in the default Blackcandy theme

  • irka
    Avatar
    Community Member
    9 Posts

    Re: conditional css Link to this post

    thank you sorted this problem anyway,,and thanks for the theme

  • Shane Garelja
    Avatar
    Community Member
    18 Posts

    Re: conditional css Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: conditional css Link to this post

    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

  • spenniec
    Avatar
    Community Member
    37 Posts

    Re: conditional css Link to this post

    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]-->");

  • B-Side
    Avatar
    Community Member
    42 Posts

    Re: conditional css Link to this post

    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

    4239 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.