css class dependant on page you're on?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Seanie
    Member
    • Jun 2003
    • 98

    css class dependant on page you're on?

    Hiya.

    I'm currently developing a website and am trying to have certain parts look change dependant on the page the page you're viewing (like different css for the active section of the navigation bar)

    can this be done using a php if statement, i cant work out how to use class1 if on test.php for example.

    Anyone got any ideas?

    Thanks


    Sean
  • diosrl
    Member
    • Feb 2005
    • 32
    • 4.0.x

    #2
    Digg into php if/else statements rather than css. You can do it by css with selectors, but for vbulletin is more complicated that way.


    PHP Code:
    <? if page=='home' echo '<li class="active">'?>
    then define that class like .active {background:#color;} It's just an example... very generic and not very server friendly.

    Comment

    • SNN
      Senior Member
      • Jul 2006
      • 856
      • 4.0.0

      #3
      If you understand this, you probably will be able to use it...
      PHP Code:
      define('class','active');    # active class
      define('iclass','inactive'); # inactive class
      switch ($page) {
         case 
      "home":
              
      $class iclass;
              
      $Aclass = class;
              break;
         default:
              
      $class iclass;
              
      $Aclass = class;
              break;

      Comment

      • Darren Gordon
        New Member
        • May 2008
        • 17

        #4
        Or you could add an extra class to the <body> tag depending on what page it is, then add per page rules.

        PHP Code:
        $page 'news';
        echo(
        "<body class=\"page_$page\">"); 
        Code:
        .page_news li {
         color: red
        }
        .page_article li {
         color: blue
        }

        Comment

        widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
        Working...
        😀
        😂
        🥰
        😘
        🤢
        😎
        😞
        😡
        👍
        👎