Hostgator coupons for up to 99% off hosting for Dynamic Drive visitors!
Advanced Search Usage Terms Submit Contact
Dynamic Drive CSS Library

CSS Library: Other: Here

CSS Generated Content

Author: Dynamic Drive

CSS2 supports the insertion of generated content, which is content that's specified using your style sheet and applied dynamically to the page according to your CSS definition. This is very useful for further decorating an element with rich content that should not be part of the page's actual markup. CSS Generated Content is accomplished using the ":before" and ":after" pseudo-classes, which denotes whether the content should be added before or after the element in question. You can insert regular "string" content or an embedded object (ie: an image). CSS2's Generated Content is supported in Mozilla/Firefox and Opera 7+, and IE7+

In our first example, we'll automatically add the decorative text ":: " in front of all H3 headers using CSS generated content, and make it red as well:

Dynamic Drive CSS Library

If you're using a capable browser, you should see the effect.

In the next example, you'll see how to include an image as part of the generated content:

The CSS:


Code Info

Rate this code:

Date Posted: 05/02/2006

Revision History: None

Usage Terms: Click here

Your Comments (34)

Got a question or need help customizing this CSS code? Post it in the CSS Forums. If you have a comment or suggestion instead, post it in the comments section below.

Comment Pages 3 of 4 pages  <  1 2 3 4 >

Nope. It's not working on IE7. It works in Firefox. Dammit Microsoft!
Posted by Tony Jolley on 02/21, 02:14 PM
Why did you state that this worked in IE at the beginning of this post without testing it? And why have people rated your code 4/5 if it doesn't work with 70% of the market share?
Posted by Michael on 03/14, 01:19 PM
Anyone figured out how to make this work in IE7? Works great in Firefox!
Posted by small biz ideas on 04/22, 04:36 PM
Can I use this code to a img tag, I used it with IE 6 and it is not rendering;
Posted by Hayesha Somarathne on 06/15, 06:06 AM
IE4+ ...please tell me your joking?
Posted by jack on 06/29, 10:11 AM
Not working in IE7.
Posted by jojo on 01/27, 11:33 AM
OK, I got confused about why the zip image showed up BEFORE the text when your style says AFTER. Your page source has both styles set to BEFORE.

But I get it now...
Posted by swggy on 03/04, 09:25 PM
i have a no image no JS corners :)
Posted by aybar on 04/04, 03:07 AM
having a hard time with these tables
Posted by Kristi on 04/10, 07:01 AM
This works on IE 8...
Posted by Bruce Smith on 10/08, 07:59 AM

Comment Pages 3 of 4 pages  <  1 2 3 4 >

Commenting is not available in this weblog entry.
Copyright 2006-2015 Dynamic Drive Read our Usage Terms before using any of the CSS codes.