如何在CSS中使用渐变创建“double”类型的边框?

时间:2015-09-22 21:42:51

标签: css css3 border gradient

我知道我可以使用border-image制作渐变实线边框,但是如何使其适用于双边框呢?

1 个答案:

答案 0 :(得分:1)

您可以使用::before::after伪元素伪造它。见fiddle

.gradient-box{
    margin: 40px auto;
	  width: 150px;
	  height: 150px;
	  background: #131313;
	  border: 10px solid transparent;
	  -moz-border-image: -moz-linear-gradient(top, #FC913A 0%, #FF4E50 100%);
	  -webkit-border-image: -webkit-linear-gradient(top, #FC913A 0%, #FF4E50 100%);
	  border-image: linear-gradient(to bottom, #FC913A 0%, #FF4E50 100%);
	  border-image-slice: 1;
	}

div::before {
  content: '';
  display: block;
  position: relative;
  left: -25px;
  top: -25px;
  height: 180px;
  width: 180px;
  border: 10px solid transparent;
	  -moz-border-image: -moz-linear-gradient(top, #FC913A 0%, #FF4E50 100%);
	  -webkit-border-image: -webkit-linear-gradient(top, #FC913A 0%, #FF4E50 100%);
	  border-image: linear-gradient(to bottom, #FC913A 0%, #FF4E50 100%);
	  border-image-slice: 1;
}
<div class="gradient-box"></div>