Moving dotted border using CSS

后端 未结 8 1877
感情败类
感情败类 2020-12-08 10:57

I have class that applies a dotted style border property to a text block at runtime. I am trying to find a solution, using CSS, that makes the border move like a gif image.

8条回答
  •  难免孤独
    2020-12-08 11:20

    Here's a pretty flexible SCSS option:

    $antlength: 50px;
    $antwidth: 10px;
    $antcolor: black;
    
    @keyframes marching-ants {
        0%   {background-position: 0 0, $antlength 100%, 0 $antlength, 100% 0;}
        100% {background-position: $antlength 0, 0 100%, 0 0, 100% $antlength;}
    }
    
    .ants {
        background-image: linear-gradient(90deg, $antcolor 50%, transparent 50%),
            linear-gradient(90deg, $antcolor 50%, transparent 50%),
            linear-gradient(0, $antcolor 50%, transparent 50%),
            linear-gradient(0, $antcolor 50%, transparent 50%);
        background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
        background-size: $antlength $antwidth, $antlength $antwidth, $antwidth $antlength, $antwidth $antlength;
        animation: marching-ants 400ms infinite linear;
    }
    

提交回复
热议问题