How to create dash dot and dash dot dot lines and rectanges in CSS

后端 未结 1 561
没有蜡笔的小新
没有蜡笔的小新 2020-12-19 19:21

How to created dash dot and dash dot dot lines and rectangles like

in CSS without using external links to images or other (inline data urls can used if ther

1条回答
  •  無奈伤痛
    2020-12-19 19:46

    You can try a combination of repeating-linear-gradient and radial-gradient

    .dash-dot {
      height:50px;
      background:
        radial-gradient(circle at center,#000 2px,transparent 3px) 5px 50%/20px 5px repeat-x,
        repeating-linear-gradient(to right,#000,#000 10px,transparent 10px,transparent 20px) center/100% 3px no-repeat 
    }
    .dash-dot-dot {
      height:50px;
      background:
        radial-gradient(circle at center,#000 2px,transparent 3px) 0px  50%/30px 5px repeat-x,
        radial-gradient(circle at center,#000 2px,transparent 3px) 10px 50%/30px 5px repeat-x,
        repeating-linear-gradient(to right,#000,#000 10px,transparent 10px,transparent 30px) center/100% 3px no-repeat;
    }

    To have a rectangle you need to repeat the same on each side:

    .dash-dot {
      height:210px;
      background:
        /*right*/
        repeating-linear-gradient(to bottom,#000,#000 10px,transparent 10px,transparent 20px) calc(100% - 1px) 0/3px 100% no-repeat,
        radial-gradient(circle at center,#000 2px,transparent 3px) 100% 5px/5px 20px repeat-y,    
        /*left*/
        repeating-linear-gradient(to bottom,#000,#000 10px,transparent 10px,transparent 20px) 1px 0/3px 100% no-repeat,
        radial-gradient(circle at center,#000 2px,transparent 3px)  0 5px/5px 20px repeat-y,
        /*top*/
        repeating-linear-gradient(to right,#000,#000 10px,transparent 10px,transparent 20px) 0 1px/100% 3px no-repeat,
        radial-gradient(circle at center,#000 2px,transparent 3px) 5px 0/20px 5px repeat-x,
        /*bottom*/
        repeating-linear-gradient(to right,#000,#000 10px,transparent 10px,transparent 20px) 0 calc(100% - 1px)/100% 3px no-repeat,
        radial-gradient(circle at center,#000 2px,transparent 3px) 5px 100%/20px 5px repeat-x;
    }

    0 讨论(0)
提交回复
热议问题