multi colored border repeating possible with css?

前端 未结 8 960
攒了一身酷
攒了一身酷 2020-12-15 14:18

I\'ve searched and can only find multiple border issues. I need to make one border with 4 colors that repeat.

8条回答
  •  执念已碎
    2020-12-15 14:24

    The future way of doing that would be border-image, as said in other answers.

    An alternative in more short term would be using pseudo-elements, with gradients:

    CSS

    .test {
      width: 500px;
      height: 100px;
      background-color: #ccc;
      position: relative;
    }
    
    .test:before, .test:after {
      content: "";
      position: absolute;
      left: 0px;
      right: 0px;
      height: 10px;
      background-image: -webkit-linear-gradient(0deg, red 20px, blue 20px, blue 40px, yellow 40px, yellow 60px, green 60px, green 80px);
      background-image: -ms-linear-gradient(0deg, red 20px, blue 20px, blue 40px, yellow 40px, yellow 60px, green 60px, green 80px);
      background-size: 80px;
    }
    
    .test:before {
      top: 0px;
    }
    .test:after {
      bottom: 0px;
    }
    

    demo

提交回复
热议问题