homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Gold Sponsor 2015!
Home / Forums Index / Code, Content, and Presentation / CSS
Forum Library, Charter, Moderators: not2easy

CSS Forum

Put an <a href=""> into a CSS sheet?

WebmasterWorld Senior Member 5+ Year Member

Msg#: 3290149 posted 8:08 pm on Mar 22, 2007 (gmt 0)

Can you put a hyperlink into a CSS sheet?



5+ Year Member

Msg#: 3290149 posted 9:48 pm on Mar 22, 2007 (gmt 0)



10+ Year Member

Msg#: 3290149 posted 11:07 pm on Mar 22, 2007 (gmt 0)


Lol :) To expand on that, no you cannot, CSS is to determine the style (presentation) of content, not to define content itself.

Defining content is the job of (X)HTML. And outputting to that medium, Javascript, PHP, ASP, etcetera.

Having said that, within limits, you can put a hyperlink reference in through CSS-through the content property.

The content property only works in standards-compliant browsers (or, at least, those nearing it) so it will not work in IE 6. But you can do stuff like this:

<p id="content-property-example">You can head down to:</p>

p#content-property-example:after { content: ' www.spoons.com.au'; }

... while not a particularly practical example (one would argue that the content in the :after pseudoclass was necessary and required in the markup itself,) that is how it is done.

There are limitations - Opera 9.10 (as far as I remember) has the best support for the :after pseudoclass and the content property, being able to import attribute values of the element, for example:

img:after { content: 'Caption: ' attr(title); }

... where this would not work in Firefox 2 (last I checked.)

Some would argue that content is never necessary in CSS - that CSS is for defining presentation, not content - and I tend to agree with them. One thing I do use content for is in my print styles: when a user prints out a page from one of the websites I've written, it dumps the href value from anchors after the anchor's content itself - thus, a printed document with good reference back to the web if necessary.


Oh, I forgot to mention: the reason I use such a thing in my print styles is degradation: it doesn't impact IE 6 negatively by not supporting it, it doesn't ruin functionality, it is merely "icing on the cake" for those UAs that can support it. I believe that "without CSS, the markup should stand up for itself." - and try to keep that in mind whenever doing CSS-Presentation.


[edited by: Setek at 11:11 pm (utc) on Mar. 22, 2007]

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / CSS
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved