Pretty simple idea, but I’m not sure how to do this. I’d like to be able to style it as one div (if possible).
How can I create an octagonal div?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The CSS used in this link is this:
It is constructed from the div element itself which is given a rectangular shape. Using the
:beforeand:afterpseudo classes, content is added to create two trapeziums that complete the octagon. Cleverly this keeps the actual tag count at just one by using the funkier bits of CSS.The origins of this technique can be found here.
Here is a quick demo. The blue part is the
:beforeCSS and the green the:afterCSS. And even better, here is a demo that allows transparent backgrounds! (thank you @GGG).