html – 如何制作一个octogonal div?

很简单的想法,但我不知道该怎么做.我希望能够将它设计成一个div(如果可能的话).

如何创建八角形div?

解决方法

this link中使用的CSS是这样的:
#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;
}

它由div元素本身构成,它具有矩形形状.使用:before和:after伪类,添加内容以创建两个完成八边形的梯形.巧妙地,这通过使用CSS的funkier位将实际标签数量保持为一.

该技术的起源可以在here找到.

Here is a quick demo.蓝色部分是:在CSS之前,绿色是:在CSS之后.甚至更好,here is a demo允许透明背景! (谢谢你@GGG).

相关文章

vue阻止冒泡事件 阻止点击事件的执行 <div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些