CSS used in this link :
#octagon { width: 100px; height: 100px; background: red; position: relative; } #octagon:before { content: ""; position: absolute; top: 0; left: 0; border-bottom: 29px solid red; border-left: 29px solid #eee; border-right: 29px solid #eee; width: 42px; height: 0; } #octagon:after { content: ""; position: absolute; bottom: 0; left: 0; border-top: 29px solid red; border-left: 29px solid #eee; border-right: 29px solid #eee; width: 42px; height: 0; }
It is built from the div itself, which is given a rectangular shape. Using the :before
and :after
pseudo-classes, the content is added to create two trapezoids that fill the octagon. Skillfully this keeps the actual tag counter only one, using more fun CSS bits.
The origins of this technique can be found here .
Here is a small demonstration . The blue part is :before
CSS and green :after
CSS. And even better, here is a demo version that allows you to use transparent backgrounds! (thanks @GGG).
source share