【问题标题】:CSS Buttons rounded on one side一侧圆形的 CSS 按钮
【发布时间】:2019-02-11 03:26:58
【问题描述】:

我必须创建一个这样的按钮:

我认为这样做很容易,但我在做圆边(左,右)时遇到了一些麻烦,我想我也很难添加一点额外的颜色。

我现在已经做了类似的东西(我觉得颜色不一样)

.home_header_buttons {
  display: flex;
}

.home_header_buttons .btn_home {
  position: relative;
  text-transform: uppercase;
  font-family: 'Poppins', sans-serif;
  font-weight: 500;
  font-size: 20px;
  letter-spacing: 2.4px;
  margin-right: -2.4px;
  line-height: 13px;
  background-color: rgba(8, 17, 23, .5);
  border: 1px solid #173c3d;
  padding: 30px 60px;
}

.home_header_buttons .btn_home:first-child {
  color: #16dcf3;
  border-right: none;
}
.home_header_buttons .btn_home:first-child::after {
  content: '';
  position: absolute;
  display: block;
  background: radial-gradient(circle at center, #007278 20%, #0b111a 100%);
  width: 1px;
  height: 90%;
  top: 50%;
  transform: translateY(-50%);
  right: 0;
  z-index: 1;
}

.home_header_buttons .btn_home:last-child {
  color: #64ffb1;
  border-left: none;
}
<div class="home_header_buttons">
    <a href="#" class="btn_home">Coaching</a>
    <a href="#" class="btn_home">Order now</a>
</div>

我试图用border-top-lef-radius和border-bottom-left-radius做一些事情,但它真的很难看。

这是它在我的开发方面的外观:

感谢您的帮助

【问题讨论】:

    标签: css


    【解决方案1】:

    您正在寻找实际上可以单独指定的各种 border-radius 属性。

    具体来说,您在 .home_header_buttons .btn_home:first-childborder-top-right-radius 上寻找 border-top-left-radiusborder-bottom-left-radius >border-bottom-right-radius.home_header_buttons .btn_home:last-child

    在我的示例中,我为每个设置了 50px 的值,这可以在下面看到:

    .home_header_buttons {
      display: flex;
    }
    
    .home_header_buttons .btn_home {
      position: relative;
      text-transform: uppercase;
      font-family: 'Poppins', sans-serif;
      font-weight: 500;
      font-size: 20px;
      letter-spacing: 2.4px;
      margin-right: -2.4px;
      line-height: 13px;
      background-color: rgba(8, 17, 23, .5);
      border: 1px solid #173c3d;
      padding: 30px 60px;
    }
    
    .home_header_buttons .btn_home:first-child {
      color: #16dcf3;
      border-right: none;
      border-top-left-radius: 50px;
      border-bottom-left-radius: 50px;
    }
    
    .home_header_buttons .btn_home:first-child::after {
      content: '';
      position: absolute;
      display: block;
      background: radial-gradient(circle at center, #007278 20%, #0b111a 100%);
      width: 1px;
      height: 90%;
      top: 50%;
      transform: translateY(-50%);
      right: 0;
      z-index: 1;
    }
    
    .home_header_buttons .btn_home:last-child {
      color: #64ffb1;
      border-left: none;
      border-top-right-radius: 50px;
      border-bottom-right-radius: 50px;
    }
    <div class="home_header_buttons">
      <a href="#" class="btn_home">Coaching</a>
      <a href="#" class="btn_home">Order now</a>
    </div>

    要添加颜色,很遗憾,您不能自己为各个角上色(因为这没有任何意义)。您需要使用border-left-colorborder-right-color。这将为边界的边缘着色:

    .home_header_buttons {
      display: flex;
    }
    
    .home_header_buttons .btn_home {
      position: relative;
      text-transform: uppercase;
      font-family: 'Poppins', sans-serif;
      font-weight: 500;
      font-size: 20px;
      letter-spacing: 2.4px;
      margin-right: -2.4px;
      line-height: 13px;
      background-color: rgba(8, 17, 23, .5);
      border: 1px solid #173c3d;
      padding: 30px 60px;
    }
    
    .home_header_buttons .btn_home:first-child {
      color: #16dcf3;
      border-right: none;
      border-top-left-radius: 50px;
      border-bottom-left-radius: 50px;
      border-left-color: blue;
    }
    
    .home_header_buttons .btn_home:first-child::after {
      content: '';
      position: absolute;
      display: block;
      background: radial-gradient(circle at center, #007278 20%, #0b111a 100%);
      width: 1px;
      height: 90%;
      top: 50%;
      transform: translateY(-50%);
      right: 0;
      z-index: 1;
    }
    
    .home_header_buttons .btn_home:last-child {
      color: #64ffb1;
      border-left: none;
      border-top-right-radius: 50px;
      border-bottom-right-radius: 50px;
      border-right-color: green;
    }
    <div class="home_header_buttons">
      <a href="#" class="btn_home">Coaching</a>
      <a href="#" class="btn_home">Order now</a>
    </div>

    如果您想扩展这些颜色,则需要使用border-top-colorborder-bottom-color,但请记住,这会为整个边缘着色:

    .home_header_buttons {
      display: flex;
    }
    
    .home_header_buttons .btn_home {
      position: relative;
      text-transform: uppercase;
      font-family: 'Poppins', sans-serif;
      font-weight: 500;
      font-size: 20px;
      letter-spacing: 2.4px;
      margin-right: -2.4px;
      line-height: 13px;
      background-color: rgba(8, 17, 23, .5);
      border: 1px solid #173c3d;
      padding: 30px 60px;
    }
    
    .home_header_buttons .btn_home:first-child {
      color: #16dcf3;
      border-right: none;
      border-top-left-radius: 50px;
      border-bottom-left-radius: 50px;
      border-left-color: blue;
      border-top-color: blue;
      border-bottom-color: blue;
    }
    
    .home_header_buttons .btn_home:first-child::after {
      content: '';
      position: absolute;
      display: block;
      background: radial-gradient(circle at center, #007278 20%, #0b111a 100%);
      width: 1px;
      height: 90%;
      top: 50%;
      transform: translateY(-50%);
      right: 0;
      z-index: 1;
    }
    
    .home_header_buttons .btn_home:last-child {
      color: #64ffb1;
      border-left: none;
      border-top-right-radius: 50px;
      border-bottom-right-radius: 50px;
      border-right-color: green;
      border-top-color: green;
      border-bottom-color: green;
    }
    <div class="home_header_buttons">
      <a href="#" class="btn_home">Coaching</a>
      <a href="#" class="btn_home">Order now</a>
    </div>

    【讨论】:

    • 谢谢你,效果很好(已经尝试过了,但是以百分比计算,所以没有成功:()你知道如何在边框上添加小颜色吗?我已经尝试了border-left-color,但它不采用圆形边框。有没有增加边框颜色区域或类似的东西?
    • 百分比值会起作用......虽然它们看起来有点奇怪;你会想要为border-radius 使用固定单位。至于颜色,标准的border-left: blue / border-left: green 可以。不幸的是,如果您想将边框的颜色扩展到圆的非常边缘,则需要使用border-top / border-bottom,它将为整个边着色。
    • 是的,我明白了,非常感谢,我觉得问这么简单的问题真的很糟糕,但无论如何,需要越来越多地学习;)
    【解决方案2】:

    除了边框半径之外,您还可以考虑使用伪元素来创建着色

    .home_header_buttons {
      display: flex;
    }
    
    .home_header_buttons .btn_home {
      position: relative;
      text-transform: uppercase;
      font-family: 'Poppins', sans-serif;
      font-weight: 500;
      font-size: 20px;
      letter-spacing: 2.4px;
      margin-right: -2.4px;
      line-height: 13px;
      background-color: rgba(8, 17, 23, .5);
      border: 2px solid #173c3d;
      padding: 30px 60px;
      box-sizing:border-box;
    }
    
    .home_header_buttons .btn_home:first-child {
      color: #16dcf3;
      border-right: none;
      border-radius:50px 0 0 50px;
    }
    .home_header_buttons .btn_home:first-child::before {
      content:"";
      position:absolute;
      top:-2px;
      bottom:-2px;
      left:-2px;
      width:70px;
      border: 3px solid red;
      border-radius:inherit;
      border-right:none;
    }
    .home_header_buttons .btn_home:first-child::after {
      content: '';
      position: absolute;
      display: block;
      background: radial-gradient(circle at center, #007278 20%, #0b111a 100%);
      width: 1px;
      height: 90%;
      top: 50%;
      transform: translateY(-50%);
      right: 0;
      z-index: 1;
    }
    
    .home_header_buttons .btn_home:last-child {
      color: #64ffb1;
      border-left: none;  
      border-radius:0 50px 50px 0;
    }
    .home_header_buttons .btn_home:last-child::before {
      content:"";
      position:absolute;
      top:-2px;
      bottom:-2px;
      right:-2px;
      width:70px;
      border: 3px solid blue;
      border-radius:inherit;
      border-left:none;
    }
    body {
     background:pink;
    }
    <div class="home_header_buttons">
        <a href="#" class="btn_home">Coaching</a>
        <a href="#" class="btn_home">Order now</a>
    </div>

    【讨论】:

    • 好的,谢谢。该死的,你们都在几分钟内解决了我的问题,而我大约 20 分钟就解决了,谢谢大家
    【解决方案3】:

    我不知道如何在外面添加颜色,但是border-radius 可以让你左右舍入。最简单的方法是圆容器的半径:

    your-container {
      border-radius: 500px;
      -webkit-border-radius: 500px;
    }
    

    【讨论】:

      猜你喜欢
      • 2016-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-25
      • 1970-01-01
      • 2019-06-09
      相关资源
      最近更新 更多