Forum Moderators: not2easy
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.
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
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.
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>
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