CSS Border Colour Into 4 Colours

前端 未结 6 1716
走了就别回头了
走了就别回头了 2021-01-12 01:49

Is there any way that I can have 4 different colours on one side of a border in CSS? I currently have

#header
{
border-color:#88a9eb;
}

I w

6条回答
  •  一生所求
    2021-01-12 02:29

    You can use box-shadow and after psuedo-element to do this

    What I did:

    I first created an :after element on the bottom, then added box-shadows horizontally with different colors

    If you want to change the strength of the border simply give more height to the :after element

    div {
      width: 200px;
      height: 100px;
      position: relative;
      background: grey;
    }
    div:after {
      bottom: 0;
      position: absolute;
      content: "";
      width: 50px;
      height: 5px;
      background: green;
      box-shadow: 50px 0 0 0 red, 100px 0 0 0 orange, 150px 0 0 0 green;
    }

    Same thing on a larger div will be like this

    div {
      width: 500px;
      height: 100px;
      background: orange;
      position: relative;
    }
    div:after {
      bottom: 0;
      position: absolute;
      content: "";
      width: 100px;
      height: 5px;
      background: green;
      box-shadow: 100px 0 0 0 darkred, 200px 0 0 0 red, 300px 0 0 0 yellow, 400px 0 0 0 tomato;
    }

提交回复
热议问题