【问题标题】:How to create a horizontal rule with square zig zags?如何创建带有方形之字形的水平规则?
【发布时间】:2021-07-06 23:51:16
【问题描述】:

你能帮我解决一下这种 hr 风格吗,比如 zip,仅限 css 我什至不知道如何开始,当然它写道我需要使用 2 个渐变。

【问题讨论】:

    标签: html css linear-gradients


    【解决方案1】:

    如下图

    .box {
      height:15px;
      background:
        repeating-linear-gradient(90deg,blue  0 5px,#0000 0 10px) top,    /* top gradient*/
        repeating-linear-gradient(90deg,#0000 0 5px,blue  0 10px) bottom, /* bottom  gradient*/ 
        linear-gradient(blue 0 0) center; /* a line in the middle */
      background-size:100% calc(100%/3); /* the 3 with the same size */
      background-repeat:no-repeat;
    }
    <div class="box"></div>

    或者

    .box {
      height:15px;
      background:
        repeating-linear-gradient(90deg,blue  0 5px,#0000 0 10px) top,   
        repeating-linear-gradient(90deg,#0000 0 5px,blue  0 10px) bottom;
      background-size:100% calc(2*100%/3); 
      background-repeat:no-repeat;
    }
    <div class="box"></div>

    另一个简化版:

    .box {
      height:15px;
      background:
        linear-gradient(90deg,blue  50%,#0000 0) top,   
        linear-gradient(90deg,#0000 50%,blue  0) bottom;
      background-size:10px calc(2*100%/3);
      background-repeat:repeat-x;
    }
    <div class="box"></div>

    【讨论】:

      【解决方案2】:

      样式来自Termani Afif's answer,只需使用hr 标签。

      hr {
        border: none;
      }
      
      .box {
        height: 15px;
        background: repeating-linear-gradient(90deg, blue 0 5px, #0000 0 10px) top, /* top gradient*/
        repeating-linear-gradient(90deg, #0000 0 5px, blue 0 10px) bottom, /* bottom  gradient*/
        linear-gradient(blue 0 0) center;
        /* a line in the middle */
        background-size: 200% calc(100%/3);
        /* the 3 with the same size */
        background-repeat: no-repeat;
      }
      <hr class="box" />

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-09-23
        • 1970-01-01
        • 2015-11-06
        • 2023-03-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-11
        相关资源
        最近更新 更多