Forum Moderators: not2easy

Message Too Old, No Replies

effect link you're currently on

hopefully easy answer

         

icpooreman

4:04 pm on Jul 22, 2005 (gmt 0)

10+ Year Member



Hey I've got a css menu bar and I want to change the syle of my link if you're currently on the link in the menu bar.

For example
say I'm on page example.com
and a link on my menu bar is <a href="example.com"> test1 </a>
I want to change the syle of the word test1

I'm just wondering if there's functionality for this in css, or if I'll have to find another way.

createErrorMsg

4:25 pm on Jul 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See msg#2, this thread [webmasterworld.com].

cEM

icpooreman

4:43 pm on Jul 22, 2005 (gmt 0)

10+ Year Member



Thanks for the info. I think you've convinced me not to do it though cause I've got a lot of pages (use includes for the menu's) and manually putting in an id into the body of all of them doesn't sound too fun. Plus I'd have to account for all of the different combo's in my css which would be ridiculously annoying. Thanks for the quick response though.

createErrorMsg

5:01 pm on Jul 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you've convinced me not to do it though

Oh no! I didn't want to do that!

There are plenty of options for doing this that don't involve manually adding things to each page. What I said in that other thread was that doing it without scripting required manual coding on each page, but if you can script, you can set up your pages to do this automatically (you mentioned includes in your last post, if those are PHP includes, you've got enough scripting knowledge to pull off current links).

One way is to use JavaScript to dynamically add a "current" id to the correct anchor on page load.

Another is to use a server side scripting language (I use PHP, some use ASP) to do the same thing only before sending the page to the browser. One very easy PHP method involves outputing an ID to the body tag that matches with the content being added. Then you use the bodyid method described in that other post to set up the current link styles. It takes a little time to get all the body#id a#id stuff set up, but once it's there, it's there for good.

I would go into more detail, but the only details that remain have to do with the various scripting languages you can use to do this, which is beyond the scope of the CSS Forum. If you want to pursue this, I would suggest posting to the JavaScript Forum [webmasterworld.com] and/or PHP Forum [webmasterworld.com]. The members who frequent and moderators who run those two forums are the best in the industry and are always eager to help.

cEM

icpooreman

6:12 pm on Jul 22, 2005 (gmt 0)

10+ Year Member



Thanks again I'm actually trying to not use any javascript although I may change my mind as that seems the easiest way to go with this.

I'm actually already using php for the includes on my pages so I'm already set up for that.

Correct me if I'm wrong but my body tag is in my html files so I wouldn't be able to add an id to it without adding a php script to all of my html files right? Which would be almost as bad as going through all of them and making an id myself. Would it be possible to do this by adding something to one of my includes already.

Although that would prob solve my css problem because I already have an include in my head section and could dynamically make my styles the same as I do the id.

createErrorMsg

8:36 pm on Jul 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Obviously, it depends on exactly what you're including and where. If there were way for you to incorporate a uniquely IDed div around the page, that would work, too. The key would be making sure that the navigation code is surrounded by the div.

In other words, say your page has the following skeletal set up...

<div id="wrapper">
<div id="header"></div>
<div id="sidebar"></div>
<div id="content"></div>
<div id="footer"></div>
</div>

Now of that, let's say you use an include file to bring in the #header code, the #navbarcode and the #footer code. Conceivably, you could add a uniquely IDed div opening tag to the END of the #header include, and then close it at the BEGINNING of the footer include. This would wrap all the stuff in between, including ther sidebar containing the links, in a uniquely IDed div, so that the output code of the web page would look like this...

<div id="wrapper">
<div id="header"></div>
<div id="YOURUNIQUEID">
<div id="navbar"></div>
<div id="content"></div>
</div>
<div id="footer"></div>
</div>

You could then use the cascade with that div in the same way you might use the body id...

div#YOURUNIQUEID a#MATCHINGLINKID {
PROPERTY:VALUE;
}

It's using the same concept as the body id, only this requires adding only a few characters to the header and footer include files (plus a scripted way to generate the unique id for the opening tag in the #header). I've never done it like this, but in theory it's pretty hands off.

almost as bad as going through all of them and making an id myself

Another option would be to use a powerful search&replace tool to run through all of your files and replace the plain <body> tag with the php code to generate a body tag with an id. Something like...

<?php echo("<body id='$this_id'>");?>

...where $this_id is a variable containing the id for that page (served through a $_GET variable in the link or however you work it). A GREP tool could swap out that code in every file in your directory in a matter of seconds.

cEM