css3鋸齒形邊框效果程式碼例項

admin發表於2017-12-04

本章節分享一段程式碼例項,它利用css3實現了邊框的鋸齒效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style type="text/css">
* {
  padding: 0;
  margin: 0;
}
.demo {
  list-style: none;
  width: 100%;
  height: 180px;
  text-align: center;
}
.demo li {
  position: relative;
  width: 20%;
  height: 100%;
  margin-right: 3%;
  background: #f60;
  display: inline-block;
}
.demo li:before, .demo li:after {
  content: "";
  position: absolute;
  top: -20px;
  display: block;
  width: 10px;
  height: 100%;
  margin-top: 20px;
  background-size: 20px 10px;
}
.demo li:before {
  left: -10px;
  background-color: #fff;
  background-position: 100% 35%;
  background-image: linear-gradient(-45deg, #f60 25%, transparent 25%, transparent), 
                  linear-gradient(-135deg, #f60 25%, transparent 25%, transparent), 
                  linear-gradient(-45deg, transparent 75%, #f60 75%), 
                  linear-gradient(-135deg, transparent 75%, #f60 75%);
}
.demo li:after {
  right: -10px;
  background-color: #f60;
  background-position: 100% 15%;
  background-image: linear-gradient(-45deg, #fff 25%, transparent 25%, transparent), 
                 linear-gradient(-135deg, #fff 25%, transparent 25%, transparent), 
                 linear-gradient(-45deg, transparent 75%, #fff 75%), 
                 linear-gradient(-135deg, transparent 75%, #fff 75%);
}
</style>
</head>
<body>
<ul class="demo">
  <li></li>
  <li></li>
  <li></li>
</ul>
</body>
</html>

相關文章