Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

css depending on link destination 1

Status
Not open for further replies.

Geronantimo

Technical User
Apr 3, 2006
79
SE
Hi,

Can anybody advise me whether it is possible to use an "if" statement to style a specific link when it appears on a page?

The link appears like this in the browser's source code:
Code:
<li class="level1 item9">
	<a href="/br/link.html" class="level1 item9">
		<span>Best Link</span>
	</a>
</li>
I am wondering how to create a conditional statement in the top of the website's template that says (in PHP terms) - "If the link's href = /br/link.html, css colour styling should be #ff0000;"

The page is created dynamically and I do not have complete control over how the link itself is created.
 
this is not a php question. you would be better off asking in the html xhtml and css forum.

but i believe the answer is absolutely not, without using javascript of course.
 
Hi

In fact it is possible with CSS.
CSS:
a[href="/br/link.html"] {
  color: #ff0000;
}
Note that the market leader browser had problem with this when I checked last time.

I would say better do it programmatically.
PHP:
<?php
$path="/br/link.html";
?>

<li class="level1 item9">
    <a href="<?php echo $path; ?>" <?php if ($path=="/br/link.html") echo "style=\"color: #ff0000;\""; ?>>
        <span>Best Link</span>
    </a>
</li>
Stupid example, but is my best for the amount of details you gave us.

Feherke.
 
Hi Feherke,

That's fantastic!

I had no idea that was possible but this will be incredibly useful.

Many thanks.
 
I agree with Geronantimo.

I've never looked at pseudo selectors properly as they have always been so inconsistently implemented. Live & learn!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top