可使用下面的代码很好的显示出这四个边框:spa
.demo-1{ width: 100px; height: 100px; border-left: 50px solid gray; border-right: 50px solid green; border-bottom: 50px solid blue; border-top: 50px solid black; }
下图对应上面的样式便可显示这四个边框究竟是如何搭配的:3d
能够发如今边角处,两个边框平分所占面积。code
将上面代码中的.demo-1
的width
和height
设置为0:blog
.demo-1{ width: 0; height: 0; border-left: 50px solid gray; border-right: 50px solid green; border-bottom: 50px solid blue; border-top: 50px solid black; }
便可显示一个正方形:ip
很显然,做出上三角很简单了,另border-left
和border-right
的颜色为透明,不设置border-top
:it
.demo-1 { width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-bottom: 50px solid blue; }
便可显示上三角:io
能够设置上、下、左、右边框的属性自由组合图形的样式。class
w3c
对这两个伪类的定义:cli
:after 选择器在被选元素的内容后面插入内容im
:before 选择器在被选元素的内容前面插入内容
请使用 content 属性来指定要插入的内容。
经过使伪类、定位能够建立出一下效果的图形:
div
代码:
.hot { background-color: #cc0000; width: 100; height: 50px; position: relative; text-align: center; }
效果见下:
代码:
.hot:before { position: absolute; width: 0; height: 0; content: ""; bottom: -12px; left: 15px; border-top: 12px solid #cc0000; border-left: 0px solid transparent; border-right: 12px solid transparent; }
注意这里使用absolute
定位
效果见下:
.hot:after { content: "头条"; color: #fff; font-size: 39px; line-height: 50px; font-family: "楷体"; font-weight: bold; }
最终效果: