If you are asking for the piece of code you shared, it clears the floating elements, say for example you have this
Demo (Without :after
pseudo to self clear parent)
Demo 2 (Using :after
with the properties to clear floating elements)
If you are asking specifically about :after
than it's just like a virtual element. It just adds content after
the element. You also have :before
which will add content before instead. The pseudo generated content is inline
by default.
This feature is really handy say when you want to add some content before or after the element, now you will say how is this really useful in real world, than consider this as 2 elements which you can just make act like a div
by making it a block level like
div.class_name:before,
div.class_name:after {
display: block;
}
Will just save you 2 elements in DOM, I would like to share few links where I've used this feature to cut down HTML...
Answer Here - Demo
Answer Here - Demo
Answer Here - Demo
MDN Reference | Support