Dynamic Expressions in CSS

 

A strange mix…

 

IE 5+ allows a strange mix of style and function called dynamic expressions. It alarms the purists, and intrigues the rule breakers.

 

It's a style, and it's a function. It's both.

 

Using CSS Dynamic Expressions:

1) Highlight the current page link.

 

Here's an example; it checks to see if the link matches the current page, and if so, returns a 'bold' font-weight.

 

 

#TOC a {font-weight: expression(boldLink(this));

 font-family: Verdana, Arial, sans-serif;

 font-size:10pt; color:navy;}
 

 

 

 

 

The style sheet calls the function boldLink();

 

 

function boldLink(el) {

if (el.href==window.location) { 

el.style.textDecoration = "none" 

return "bold" 

}

 

 

 

 

 

 

A mondo thanks and credit for the boldLink() script to: SiteExperts.com.

 

 

Another way to use dynamic expressions:

2) Expand the URL when printing.

 

It might be helpful to show the full, expanded URL of a link when printing a page. First, create the style that calls the function - this particular example uses the unique identifier #TOC, to narrow it's use to all links within that <DIV>.

 

 

 <STYLE>

 #TOC a {font-style: expression(showLink(this));

 font-family: Verdana, Arial, sans-serif;

 font-size:10pt; color:navy;}

 </STYLE> 

 

 

 

 

 

Here is the function we call from the stylesheet:

 

 

<script language="JavaScript1.2" type="text/javascript">

<!--

var pattern = "/%20/g";

function showLink(el) {

var tmp = "";

 

var strInnerHTML = String(el.innerHTML);

 

if (strInnerHTML.indexOf(" (url: ") == -1) {

tmp = " (url: " + el.href + ") "; 

tmp= tmp.replace(pattern," ") ;  

el.style.textDecoration = "none"; 

 el.innerHTML = (el.innerHTML + tmp);

 

 return "italic"

  }

}

//-->

</script>

 

 

 

 

 

Here is a simple link within a <DIV> tag.

 

 

<div id="TOC">

Here is a link:

<a href="thispage.htm">this page</a>

<br>&nbsp;

<br>

A second link"

<a href="thatpage.htm">that page</a>

</div>

 

 

 

 

 

By now, you have probably realized that these functions could be evoked just as easily from a regular JavaScript function when the page is printed.

 

The Dangers of Dynamic Expressions in CSS. . . ?

The entire concept of Dynamic Expressions built into a style sheet bothers a lot of IT professionals. Basically, it ignores the revered separation of content and format, form and function. The issues are twofold:

Security: now style sheets can pose the same security risks as scripts, and sites with user-submitted content are exposed to scripting risks.

Aesthetics: now active content exists where you least expect it. Style sheets now depend on scripts to display properly.

These issues are more of a concern for Internet management and web applications developers; it might not be as much of a concern to Help and ebook authors, and for users on company intranets.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

Copyright Copperfield Publishing, 2001, 2002Some relevant topics, perhaps...about the automated lookup system we use on every page...