css實現的交叉邊框效果

antzone發表於2017-03-07

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

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style type="text/css">
.main{
  width:200px;
  height:200px;
  position:relative;
  float:left;
  margin:20px;
}
.box1:after{
  content:'';
  position:absolute;
  width:100%;
  height:1px;
  background-color:#000;
  top:10px;
  box-shadow:#000 0 170px;
}
.box1:before{
  content:'';
  position:absolute;
  height:100%;
  width:1px;
  background-color:#000;
  left:10px;
  box-shadow:#000 170px 0px;
}
.box2{
  background-image:linear-gradient(
    to right, 
    rgba(0,0,0,0) 0px, 
        rgba(0,0,0,0) 20px,
                 
    rgba(0,0,0,1) 20px,
        rgba(0,0,0,1) 21px,
                 
        rgba(0,0,0,0) 21px,
        rgba(0,0,0,0) 180px,
                 
        rgba(0,0,0,1) 180px,
        rgba(0,0,0,1) 181px,
                 
        rgba(0,0,0,0) 181px,
    rgba(0,0,0,0) 200px),
                 
                 
                 
    linear-gradient(
    to bottom, 
    rgba(0,0,0,0) 0px, 
        rgba(0,0,0,0) 20px,
                 
    rgba(0,0,0,1) 20px,
        rgba(0,0,0,1) 21px,
                 
        rgba(0,0,0,0) 21px,
        rgba(0,0,0,0) 180px,
                 
        rgba(0,0,0,1) 180px,
        rgba(0,0,0,1) 181px,
                 
        rgba(0,0,0,0) 181px,
    rgba(0,0,0,0) 200px);
}
</style>
</head>
<body>
<div class="main box1"></div>
<div class="main box2"></div>
</body>
</html>

相關文章