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 2 of 4 pages  <  1 2 3 4 >

Also, sph, IE6 (and, I expect, 5) doesn't always display an element with padding and a background image correctly if the element is inline, and breaks over more than one line. Firefox correctly shows the image at the very end/beginning of the line as specified, but IE will sometimes try to position the image as though the element display is set to block! I'm having some trouble finding a way around this one.
Posted by Jordan Gray on 07/31, 07:13 AM
it doesn't work on IE7+ beta 3
Posted by miguel on 08/09, 05:33 AM
Nope NOT in IE7 neither beta or release.
A shame cause this CSS feature is mandatory for content/style separation
Posted by Ezion on 10/07, 09:25 PM
So does this imitate an iframe? i've been messing with iframes and am trying to banish the bottom scroll.
So can this little piece of css pull in a formatted table? Sure sounds close?
Posted by Eric on 10/11, 06:33 PM
Argh!!! not on IE7? I just downloaded it hoping I'd be able to use it, and that people using IE would be able to view my site with it. Could someone perhaps make an IE add-on which would enable it?
Posted by Samuel Loy on 12/16, 11:40 AM
Re: IE
Just shows that Microsoft has the whole world duped into thinking that they are leaders in software development. IE, in all of its flavors, is the bane of my existance as a web developer.
Posted by ToddR on 12/20, 10:12 AM
IE7 has a different way of showing this type of content, but I don't know it!
Posted by Titan602 on 12/23, 08:42 AM
Any one see a difference using FireFox?
Posted by search engine on 12/24, 07:43 AM
Since unfortunately half the world is using IE is anyone aware of a work around for getting generated content to display at all in IE6?
Posted by love blah on 01/16, 06:27 PM
browser problem, use after a few year !
Posted by gazete gazeteler on 02/05, 11:11 AM

Comment Pages 2 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.