{"id":9516,"date":"2011-06-13T11:42:39","date_gmt":"2011-06-13T18:42:39","guid":{"rendered":"http:\/\/css-tricks.com\/?p=9516"},"modified":"2021-08-19T11:50:26","modified_gmt":"2021-08-19T18:50:26","slug":"pseudo-element-roundup","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/pseudo-element-roundup\/","title":{"rendered":"A Whole Bunch of Amazing Stuff Pseudo Elements Can Do"},"content":{"rendered":"\n

It’s pretty amazing what you can do with the pseudo-elements ::before<\/code> and ::after<\/code><\/a>. For every element on the page, you get two more free ones that you can do just about anything another HTML element could do. They unlock a whole lot of interesting design possibilities without negatively affecting the semantics of your markup. Here’s a whole bunch of those amazing things. A roundup, if you will.<\/p>\n\n\n

Give you multiple background canvases<\/h3>\n\n\n
\"\"<\/figure>\n\n\n\n

Because you can absolutely position pseudo-elements relative to their parent element, you can think of them as two extra layers to play with for every element. Nicolas Gallagher shows us<\/a> lots of applications of this, including multiple borders, simulating CSS3 multiple backgrounds, and equal height columns.<\/p>\n\n\n

Expand the number of shapes you can make with a single element<\/h3>\n\n\n
\"\"<\/figure>\n\n\n\n

All of the shapes above and many more<\/a> can be created with a single element, which makes them actually practical. As opposed to those “make a coffee cup with pure CSS!” things that use 1,700 divs, which are neat but not practical.<\/p>\n\n\n\n

Here’s an example of a six-pointed star:<\/p>\n\n\n\n

#star-six {\n  width: 0;\n  height: 0;\n  border-left: 50px solid transparent;\n  border-right: 50px solid transparent;\n  border-bottom: 100px solid red;\n  position: relative;\n}\n#star-six:after {\n  width: 0;\n  height: 0;\n  border-left: 50px solid transparent;\n  border-right: 50px solid transparent;\n  border-top: 100px solid red;\n  position: absolute;\n  content: \"\";\n  top: 30px;\n  left: -50px;\n}<\/code><\/pre>\n\n\n