【问题标题】:CSS circle with double border带双边框的 CSS 圆圈
【发布时间】:2017-12-14 14:05:30
【问题描述】:

我刚收到 Designer 的 PSD,大部分部分都可以通过 CSS 实现,我只尝试做一个,对我来说似乎很难做的是一个有 2 个边框的圆圈。 我可以使用 bg image 方法,但最好使用 CSS3 来实现。

使用 CSS 的主要原因之一是在几个不同的元素上使用了相同的边框。

【问题讨论】:

    标签: html css border css-shapes


    【解决方案1】:

    您可以使用::before::after 伪元素来创建此形状:

    .btn-holder {
      background: darkgreen;
      padding: 30px;
    }
    
    .btn {
      background: transparent;
      justify-content: center;
      align-items: center;
      position: relative;
      color: #fff;
      display: flex;
      height: 100px;
      width: 100px;
    }
    
    .btn,
    .btn::after {
      border: 1px solid #fff;
      border-radius: 100%;
    }
    
    .btn::after {
      position: absolute;
      content: '';
      width: 100%;
      height: 100%;
      left: 0;
      top: -4px;
    }
    <div class="btn-holder">
      <button type="button" class="btn">Register</button>
    </div>

    【讨论】:

      【解决方案2】:

      您可以尝试 :after 为圆圈制作 2 个边框:

      .green{
        width: 300px;
        height: 300px;
        background-color: green;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      
      .circle {
        position: relative;
        width: 150px;
        height: 150px;
        border: 1px solid #fff;
        border-radius: 50%;
      }
      
      .circle::after {
        content: '';
        width: 150px;
        height: 150px;
        border: 1px solid #fff;
        border-radius: 50%;
        display: block;
        margin: -4px 2px;
      }
      <div class="green">
        <div class="circle"></div>
      </div>

      【讨论】:

        【解决方案3】:

        您可以将单个元素与 box-shadow - CSS | MDN 一起使用

        button{
          position:relative;
          margin: 20px auto;
          border-radius: 50%;
          border: 2px solid transparent;
          border-bottom: none;
          border-top: none;
          width: 100px;
          height: 100px;
          color: red;
          box-shadow: -1px -1px currentcolor, 
                       1px 1px currentcolor,
                       
                       inset -1px 1px currentcolor, 
                       inset 1px -1px currentcolor;
          display: block;
          background-color: #fd999952;
          background-clip: padding-box;
          font-weight: bolder;
          outline: none;
        }
        &lt;button type="button" class="btn"&gt;Register&lt;/button&gt;

        【讨论】:

          猜你喜欢
          • 2016-01-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-05-30
          • 1970-01-01
          • 2012-10-15
          • 1970-01-01
          相关资源
          最近更新 更多