Create a border gradient for each of the 4 borders

前端 未结 2 1510
余生分开走
余生分开走 2020-12-12 01:56

I want to create the same linear gradient for each border.

The border gradient with 5 colors starts from

transparent to white to bla         


        
2条回答
  •  隐瞒了意图╮
    2020-12-12 02:48

    You could also do this with multiple linear-gradients as backgrounds and position them as required like in the below snippet.

    To change the size/width of the border, modify the 20px value in the background-size. (Note: Depending on the desired output, you may have to change the linear-gradient percentages also when you change the size. But that should be reasonably straight-forward to do.)

    background-size: 100% 20px, 100% 20px, 20px 100%, 20px 100%;
    

    Gradients on the whole have no support in IE 9 but should work in IE 10+. Border-image on the other hand works only from IE 11 upwards.

    .border-image {
      height: 200px;
      width: 200px;
      background: -webkit-linear-gradient(0deg, transparent 10%, white 10%, black 50%, white 90%, transparent 90%), -webkit-linear-gradient(0deg, transparent 10%, white 10%, black 50%, white 90%, transparent 90%), -webkit-linear-gradient(90deg, transparent 10%, white 10%, black 50%, white 90%, transparent 90%), -webkit-linear-gradient(90deg, transparent 10%, white 10%, black 50%, white 90%, transparent 90%);
      background: -moz-linear-gradient(0deg, transparent 10%, white 10%, black 50%, white 90%, transparent 90%), -moz-linear-gradient(0deg, transparent 10%, white 10%, black 50%, white 90%, transparent 90%), -moz-linear-gradient(90deg, transparent 10%, white 10%, black 50%, white 90%, transparent 90%), -moz-linear-gradient(90deg, transparent 10%, white 10%, black 50%, white 90%, transparent 90%);
      background: linear-gradient(90deg, transparent 10%, white 10%, black 50%, white 90%, transparent 90%), linear-gradient(90deg, transparent 10%, white 10%, black 50%, white 90%, transparent 90%), linear-gradient(0deg, transparent 10%, white 10%, black 50%, white 90%, transparent 90%), linear-gradient(0deg, transparent 10%, white 10%, black 50%, white 90%, transparent 90%);
      background-repeat: no-repeat, no-repeat, no-repeat, no-repeat;
      background-size: 100% 20px, 100% 20px, 20px 100%, 20px 100%;
      background-position: 0px 0px, 0px 100%, 0px 0px, 100% 0px;
      padding: 20px;
    }
    Some Test Content

提交回复
热议问题