FORUMS: list search recent posts

class for active page?

COW Forums : Web Design

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Bret Williams
class for active page?
on Oct 17, 2005 at 4:09:10 pm

I was wondering if there's a class for active page. For example, if the active page is the same as the link, then use a particular class.

I know it's been done in the past by javascript, but I was wondering if CSS can do it now.

I've got a menu, and it has CSS rollover states (:hover) and I thought the :active state sounded like what I want, but it doesn't seem to do anything. The hover state can still work, but I'd just like to change the color, letting the visitor know that's the section they're in.

Thanks!


Return to posts index

Curtis Thompson
Re: class for active page?
on Oct 18, 2005 at 5:01:49 pm

hello...

i'm sorta following you here...i think.

the active bit of the link is when you click on it and hold your mouse - so that brief second that it changes color it can be set (not too useful, but if you're really into colors and presentation then you can control it - it would also be the color if you tabbed onto the link...

there's no good way for css to evaluate what page it's on and show a style accordingly. what i often do is make a copy of my link style and add "On" to the style name and then (if it's php, etc. header), do the old if script name == page url then also echo "On" to the css class - then the right style is called for that page and it shows as on...

is that what you were thinking of? sounds like you already knew how to do it, though...

sitruc


Return to posts index

Bret Williams
Re: class for active page?
on Oct 18, 2005 at 6:35:09 pm

Darn. Was hoping I was missing something. Good info on active. Yeah, useless. I uually call that the "down" state so I didn't pick up on "active" meaning that.

On the JS, I know how it's done, but haven't been able to find a simple script for it. Is there a simple line of javascript that can be added to each menu item? I can handle adding the CSS no problem.

Specifically, the site I'm working on... hownet.lunarpages.net/retail

The menus on the left do what you're describing, but I don't know enough javascript to decipher how they do it. It's a DW script extension. I can of course change their CSS styles.

I can use the same extension to create horizontal menus, but I don't need the pull downs, and I've already got the CSS how I want it, etc.


Return to posts index


Curtis Thompson
Re: class for active page?
on Oct 18, 2005 at 7:05:08 pm

hello...

i'd do something like this:

not on that page:

<div><a class="navLink" href="/retail/cretailsalesskills.php">Retail Sales Skills</a></div>

on that page:

<div><a class="navLinkOn" href="/retail/cretailsalesskills.php">Retail Sales Skills</a></div>

so then the trick becomes updating that with php to show the "On" if you're on that page...so something like this should work:

<div><a class="navLink<?= ($_SERVER['SCRIPT_NAME'] == "/retail/cretailsalesskills.php")) ? "On" : "" ?>" href="/retail/cretailsalesskills.php">Retail Sales Skills</a></div>

thoughts?

sitruc


Return to posts index

Bret Williams
Re: class for active page?
on Oct 19, 2005 at 2:21:45 am

Well, I don't speak PHP but I can understand it I think. But I think my issue might be more complex than your example. I'm looking for a way to highlight the horizontal main menu links. So it has to look for a particular directory, not a specific page. To use the retail page as an example, the link is simply /retail. Which takes you to index.php. But I want it highlighted for all the pages in the retail section.

The links on the left already have this function because of the extension I purchased which creates the twirl down menus.

In the example you give, it seems that this is how it works... (the class I use is "biglinks")

class="biglinks(then you insert the script here that says if the current page is so and so then print "ON," otherwise, then print "" (nothing). That I understand. The script is filling in the end of the class with either ON or nothing, which will determine it's appearance. Exactly what I looking to do. What I don't understand is the $_SERVER['SCRIPT_NAME'] part. Is that a built in function, or am I to call on a script that will determine the page or directory I'm viewing?


Return to posts index

Curtis Thompson
Re: class for active page?
on Oct 19, 2005 at 2:32:38 am

hello...

[Bret Williams] "s that a built in function, or am I to call on a script that will determine the page or directory I'm viewing?"

the $_SERVER array is a built-in array in php that has a wide variety of useful parameters. you could figure out the directory by using that same script name param and the php dirname function (http://us2.php.net/dirname)...

you can find some other useful vars by making a dummy file and putting the php info at the top:

<?= phpinfo() ?>

you'll see all the params (and a bunch of other stuff) that php knows about each script. you can try putting the script in different dirs (say you do the above and save it as phpinfo.php) to see how the variables change...

make sense?

sitruc


Return to posts index


Bret Williams
Re: class for active page?
on Oct 19, 2005 at 4:50:57 am

Whoops posted that last reply to the wrong post. Anyway. Got it. It's all functional.


Return to posts index

Bret Williams
Re: class for active page?
on Oct 19, 2005 at 4:04:41 am

Well, I have no idea what you're talking about. But I made it happen somehow anyway. Great little piece of code to add to the arsenal.

You had an extra closing parenthesis, and I had to figure out how to add parentheses when I added he dirname in front of what you had. The link to the php manual helped me get it.

I think. :)

Thanks!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]