做一個門票或者郵票:效果圖
1.html就是兩個div
2.具體css代碼
1 <style> 2 /*左側長方體基本樣式*/ 3 div:nth-of-type(1){ 4 width: 300px; 5 height: 200px; 6 background-color: red; 7 float: left; 8 } 9 /*右側長方體基本樣式*/ 10 div:nth-of-type(2){ 11 width: 100px; 12 height: 200px; 13 background-color: blue; 14 float: left; 15 position: relative; 16 } 17 /*第一個偽元素:before是遮蓋上邊緣的圓形,當然也可以是別的形狀*/ 18 div:nth-of-type(2)::before{ 19 /*必須添加content屬性,否則后期看不到*/ 20 content: ""; 21 /*默認是行級元素,如果想設置寬高,必須轉換成塊級元素*/ 22 position: absolute; 23 width: 20px; 24 height: 20px; 25 background-color: #fff; 26 border-radius: 10px; 27 left: -10px; 28 top: -10px; 29 } 30 /*第一個偽元素:after是遮蓋下邊緣的圓形,同上也可以是別的形狀*/ 31 div:nth-of-type(2)::after{ 32 /*必須添加content屬性,否則后期看不到*/ 33 content: ""; 34 /*默認是行級元素,如果想設置寬高,必須轉換成塊級元素*/ 35 position: absolute; 36 width: 20px; 37 height: 20px; 38 background-color: #fff; 39 border-radius: 10px; 40 left: -10px; 41 bottom: -10px; 42 } 43 </style>