css條紋邊框程式碼例項

antzone發表於2017-04-12

分享一段程式碼例項,它利用不同的方式實現了條紋邊框效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style type="text/css">
div {
  position: relative;
  width: 180px;
  height: 180px;
  border: 20px dashed #2196f3;
  margin: 50px;
  float: left;
}
.style_one {
  background: #9c27b0;
}
.style_one::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: #fff;
}
.style_two {
  background: #fff;
  background-clip: padding-box;
}
.style_two::before {
  content: "";
  position: absolute;
  top: -20px;
  left: -20px;
  bottom: -20px;
  right: -20px;
  background: #996699;
  z-index: -1;
}
.style_three {
  border-radius: 50%;
  background-image: radial-gradient(#ffffff 90px, rgba(0, 0, 0, 0) 90px);
  background-repeat: no-repeat;
}
.style_three::after {
  content: "";
  position: absolute;
  top: -20px;
  left: -20px;
  right: -20px;
  bottom: -20px;
  background: deeppink;
  z-index: -1;
  border-radius: 50%;
}
.style_shadow {
  background: yellowgreen;
  box-shadow: inset 180px 0 0 0 #fff;
}
.style_outline {
  border: 20px solid #2196f3;
}
.style_outline::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  outline: 20px dashed #ffc107;
}
</style>
</head>
<body>
  <!-- 中間白色底色是偽元素 -->
  <div class='style_one'></div>
  <!-- 中間白色底色是背景色 -->
  <div class='style_two'></div>
  <!-- 徑向漸變 -->
  <div class='style_three'></div>
  <!-- 內陰影 -->
  <div class='style_shadow'></div>
  <!-- outline + 偽類 -->
  <div class='style_outline'></div>
</body>
</html>

相關文章