【问题标题】:How to fill the horizontal space between two divs using dotted/dashed line using CSS如何使用 CSS 使用虚线/虚线填充两个 div 之间的水平空间
【发布时间】:2022-02-16 02:40:18
【问题描述】:

this is what I want to achieve

我尝试这样做,但无法更改破折号之间的间距。 此外,圆圈和虚线的大小不会根据屏幕大小而变化。

这是我到目前为止所做的: see the gap difference between the dashes

代码如下:

      <div id="getStarted" className={styles.getStarted}>
    <h3>How to get started?</h3>
    <div className={styles.Icons}>
      <div className={styles.circle}>
      
      </div>
      <div className={styles.dash}></div>
      <div className={styles.circle}>
      
      </div>
       <div className={styles.dash}></div>
       <div className={styles.circle}>
      
      </div>
    </div>
  </div>

这是 CSS 样式:

    .getStarted {
  justify-content: center;
  align-items: center;
  text-align: center;

  h3 {
    color: #006ebe;
    font-size: 2.3vw;
    margin-bottom: 100px;
  }

  .Icons {
      gap: 2vw;
    display: flex;
    justify-content: center;

.circle {
  border-radius: 50%;
  width: 20px;
  height: 20px;
  padding: 10px;
  background: #0093ff;
  border: 3px solid #0093ff;
  color: white;
  text-align: center;
  font: 20px Poppins, sans-serif;
  font-weight: 600;
  line-height: 22px;
}
    .dash {
      
      width: 10%;
      border-top: 4px dotted #006ebe;
      margin-top: 20px;
      transform: rotate(-0.07deg);
    }
  }
}

【问题讨论】:

    标签: html css reactjs sass styling


    【解决方案1】:

    您的模板看起来很像使用stroke-dasharray 和圆形strike-linecap 的svg 行

    .getStarted {
      justify-content: center;
      align-items: center;
      text-align: center;
    }
    h3 {
      color: #006ebe;
      font-size: 2.3vw;
      margin-bottom: 100px;
    }
    
    .Icons {
      gap: 2vw;
      display: flex;
      justify-content: center;
    }
    
    .circle {
      border-radius: 50%;
      width: 20px;
      height: 20px;
      padding: 10px;
      background: #0093ff;
      border: 3px solid #0093ff;
      color: white;
      text-align: center;
      font: 20px Poppins, sans-serif;
      font-weight: 600;
      line-height: 22px;
    }
    
    .dash {
      width: 10%;
      transform: rotate(-0.07deg);
    }
    .dash line {
      stroke: #0093ff;
      stroke-dasharray: 0.5 3.2;
      stroke-linecap: round;
    }
    <div id="getStarted" class="getStarted">
      <h3>How to get started?</h3>
      <div class="Icons">
        <div class="circle">
    
        </div>
        <svg class="dash" viewBox="-10 -5 20 10"><line x1="-9" x2="9"></line></svg>
        <div class="circle">
    
        </div>
         <svg class="dash" viewBox="-10 -5 20 10"><line x1="-9" x2="9"></line></svg>
         <div class="circle">
    
        </div>
      </div>
    </div>

    【讨论】:

    • 如果您想要全圆点,可以尝试将 svg 嵌入为背景图像,类似于此工具的操作方式:kovart.github.io/dashed-border-generator(但偏移 cy 以完全渲染)(最好使用 rect我最终得到的是url("data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect y='5%25' x='5%25' width='90%25' height='90%25' fill='none' stroke='black' stroke-width='18' stroke-dasharray='0.1%2c40' stroke-dashoffset='4' stroke-linecap='round'/%3e%3c/svg%3e"))
    • 非常感谢,上面的 svg 解决方案对我有用。
    • 虽然它解决了问题,但你能建议我如何随着宽度的增加而增加点的数量吗?目前,当屏幕尺寸增加时,线条的宽度会增加,但点数保持不变,因此会在圆圈和线条之间产生大量空白
    • 似乎你只能使用一些javascript来获得(响应点和受控点间距)。 (例如更改 svg 中的线宽)
    • 我改变了 x1 和 x2 的值,它起作用了。
    【解决方案2】:

    通过使用此答案 How to increase space between dotted border dots 并更改 background-size 属性,您可以更改破折号之间的间隙。通过使用vw 单元,您可以通过调整页面大小来更改破折号。

    .getStarted {
      justify-content: center;
      align-items: center;
      text-align: center;
    }
    h3 {
      color: #006ebe;
      font-size: 2.3vw;
      margin-bottom: 100px;
    }
    
    .Icons {
      gap: 2vw;
      display: flex;
      justify-content: center;
    }
    .circle {
      border-radius: 50%;
      width: 20px;
      height: 20px;
      padding: 10px;
      background: #0093ff;
      border: 3px solid #0093ff;
      color: white;
      text-align: center;
      font: 20px Poppins, sans-serif;
      font-weight: 600;
      line-height: 22px;
    }
    .dash {
      width: 10%;
      background-image: linear-gradient(
        to right,
        #0093ff 35%,
        rgba(255, 255, 255, 0) 0%
      );
      background-position: center;
      background-size: 1.6vw 0.6vw;
      background-repeat: repeat-x;
    }
    <div id="getStarted" class='getStarted'>
      <h3>How to get started?</h3>
      <div class='Icons'>
          <div class=' circle'>
    
      </div>
      <div class='dash'></div>
      <div class='circle'>
    
      </div>
      <div class='dash'></div>
      <div class='circle'>
    
      </div>
    </div>
    </div>

    【讨论】:

      【解决方案3】:

      您可以更改 CSS。

      CSS 示例:

      .getStarted {
        justify-content: center;
        align-items: center;
        text-align: center;
      }
      
        h3 {
          color: #006ebe;
          font-size: 2.3vw;
          margin-bottom: 100px;
        }
      
        .Icons {
          display: flex;
          justify-content: center;
        }
      
      .circle {
        border-radius: 50%;
        width: 20px;
        height: 20px;
        padding: 10px;
        background: #0093ff;
        border: 3px solid #0093ff;
        color: white;
        text-align: center;
        font: 20px Poppins, sans-serif;
        font-weight: 600;
        line-height: 22px;
        margin-left: 6px;
        margin-right: 6px;
      }
          .dash {
            
        width: 20%;
        border-top: 4px dotted #006ebe;
          margin: 20px 2px 0 2px;
        transform: rotate(-0.07deg);
          }
      

      HTML

            <div id="getStarted" className={styles.getStarted}>
          <h3>How to get started?</h3>
          <div className={styles.Icons}>
            <div className={styles.circle}>
            
            </div>
            <div className={styles.dash}></div>
            <div className={styles.circle}>
            
            </div>
             <div className={styles.dash}></div>
             <div className={styles.circle}>
            
            </div>
          </div>
        </div>
      

      .getStarted {
        justify-content: center;
        align-items: center;
        text-align: center;
      }
      
        h3 {
          color: #006ebe;
          font-size: 2.3vw;
          margin-bottom: 100px;
        }
      
        .Icons {
          display: flex;
          justify-content: center;
        }
      
      .circle {
        border-radius: 50%;
        width: 20px;
        height: 20px;
        padding: 10px;
        background: #0093ff;
        border: 3px solid #0093ff;
        color: white;
        text-align: center;
        font: 20px Poppins, sans-serif;
        font-weight: 600;
        line-height: 22px;
        margin-left: 6px;
        margin-right: 6px;
      }
          .dash {
            
        width: 20%;
        border-top: 4px dotted #006ebe;
          margin: 20px 2px 0 2px;
        transform: rotate(-0.07deg);
          }
      <div class="getStarted" id="getStarted">
      <h3>How to get started?</h3>
      
      <div class="Icons">
      <div class="circle"></div>
      
      <div class="dash"></div>
      
      <div class="circle"></div>
      
      <div class="dash"></div>
      
      <div class="circle"></div>
      </div>
      </div>

      【讨论】:

        猜你喜欢
        • 2023-03-22
        • 1970-01-01
        • 2019-12-12
        • 2017-11-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-01
        相关资源
        最近更新 更多