A[href="http://www.w3.org/"] { color: #000; }
This will take ANY link that points to http://www.w3.org/ and give it a color of black. This will do that ONLY FOR THOSE LINKS. Cool eh?
Another CSS2 attribute we're going to use is :after. Actualy, this is a psuedo-element. This allows us to insert generated content before or after the declared elements content. Got that?
Okay, so what we have so far is thus:
blockquote[cite]:after { }
Which will tell the browser to render stuff after any blockquote with a cite attribute.
But how do we get the URL written in there?
We turn to the content property.
Content can be a string, URI, counter, or an attribute. It applies ONLY to :before and :after pseudo elements.
So by writing this into our CSS declaration
content: "Quote from: " attr(cite);
you'll see that the text "Quote from: http://www.foo.bar" written across the bottom of your blockquote. Additional styling is easy enough.
(the following example won't work if you're using IE. )
This function returns as a string the value of attribute X for the subject of the selector. The string is not parsed by the CSS processor. If the subject of the selector doesn't have an attribute X, an empty string is returned. The case-sensitivity of attribute names depends on the document language. Note. In CSS2, it is not possible to refer to attribute values for other elements of the selector.Attached for display are my full blockquote styles.
blockquote[cite]:after {
content: "Quote from: " attr(cite);
display: block;
border-top: 1px solid #999;
color: #999;
margin: 1em 0 0;
padding: .5em 0 0;
font-size: .8em;
font-weight: bold;
}
blockquote {
background: #eee;
margin: 20px;
padding: .5em;
margin-top: 0px;
border: 1px dotted #999;
}
Comments are Open (5)
Posted at 11:29 AM
Comments
Sam
I've done that too, but it bugs me how you can't select the content in Gecko-based browsers. It would also be nice to make it a link; but that also doesn't work.
Posted by: Sam | November 13, 2003 03:41 PM
Xian
Going with what Sam said, CSS inserted content also can't be selected in Safari.
Other than that, the only other thing I would suggest would be adding overflow:hidden; to blockquote[cite]:after which would keep extra long URLs from getting out of hand.
But until the selectability issues are fixed in the browsers, I think the JS method does a much better job of it:
http://www.1976design.com/blog/archive/2003/11/10/46/
Posted by: Xian | November 13, 2003 04:19 PM
JosÈ Jeria
Interesting article, isnt it posible to make the link clickable?
Posted by: JosÈ Jeria | November 16, 2003 08:03 AM
FranÃ?ois
Nice to quote a weblink, but if yu quote a person, problems :
- It won't validate if there's a space somewhere (eg: John Smith)
- BBEdit tells me to encode the space to %20, so did I. But then the %20 appears in browsers (eg: John%20Smith).
So the trick is nice, I use it myself (see my link), but it's stuck in MSIE, and it's not valid in many cases.
I'm thinking of going back to a blockquote/cite, unless you have a trick to make it valid.
Posted by: FranÃ?ois | February 14, 2004 07:56 PM
Jeff
That's quite useful. Thanks.
You can also do a similar thing for links, acronym and abbr too. Put the appropriate attribute in parentheses on the print stylesheet so they can always get back to it.
Posted by: Jeff | November 20, 2004 12:18 PM