css3邊框顏色漸變且四角有內凹圓形程式碼例項

admin發表於2017-04-07

本章節分享一段程式碼例項,它實現了邊框顏色漸變且四角有內凹的圓形效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
div {
  box-sizing: border-box;
}
body {
  background-color: #333;
  padding: 0;
}
.main {
  padding: 10px;
  position: fixed;
  height: 600px;
  width: 400px;
  background: #345;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}
.main .wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  background: -webkit-linear-gradient(left, #fd5, #080);
  background: linear-gradient(left, #fd5, #080);
}
svg {
  width: 100%;
  height: 100%;
}
.outer-wrapper {
  width: 100%;
  height: 100%;
  background: #345;
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  -webkit-clip-path: url("#clip-path");
  clip-path: url("#clip-path");
}
.content {
  color: #fff;
  text-align: center;
  font-size: 48px;
  line-height: 100px;
  width: calc(100% - 2px);
  height: calc(100% - 2px);
  background: #345;
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}
.inner {
  width: 100%;
  height: 100%;
  background: #333;
  position: absolute;
  top: 50%;
  left: 50%;
  background: -webkit-linear-gradient(left, #fd5, #080);
  background: linear-gradient(left, #fd5, #080);
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  -webkit-clip-path: url("#clip-path-inner");
  clip-path: url("#clip-path-inner");
}
</style>
</head>
<body>
<div class="main">
  <div class="wrapper">
    <div class="content">
      Title
      <div class="inner">
        <svg>
          <defs>
            <clipPath id="clip-path-inner">
              <circle cx="0" cy="0" r="10"></circle>
              <circle cx="0" cy="100%" r="10"></circle>
              <circle cx="100%" cy="0" r="10"></circle>
              <circle cx="100%" cy="100%" r="10"></circle>
            </clipPath>
          </defs>
        </svg>
      </div>
    </div>
    <div class="outer-wrapper"></div>
    <svg>
      <defs>
        <clipPath id="clip-path">
          <circle cx="0" cy="0" r="10"></circle>
          <circle cx="0" cy="100%" r="10"></circle>
          <circle cx="100%" cy="0" r="10"></circle>
          <circle cx="100%" cy="100%" r="10"></circle>
        </clipPath>
      </defs>
    </svg>
  </div>
</div>
</body>
</html>

相關文章