43

我只想为按钮的上半部分制作圆角。

border-radius我知道如何使用和为所有侧面制作圆角-webkit-border-radius

但只喜欢上半部分有角。

我需要一些关于如何在 CSS 中执行此操作的指导。

4

7 回答 7

45

您可以使用以下样式规则:

border-top-left-radius
border-top-right-radius

注意:该border-radius规则在没有-webkit-位的情况下有效。

于 2012-07-14T12:26:52.177 回答
45

当我想绕过特定的角落时,我使用下面的代码

border-radius: 10px     10px      0           0;
            // top-left top-right bottom-right bottom-left. 
于 2012-07-17T01:56:20.213 回答
9

这是我喜欢使用的模式:

CSS

.round-corners-5px{
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
}
.round-corners-10px{
    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
    border-radius: 10px;
}
.unround-top-corners{
    -webkit-border-top-left-radius: 0px;
    -webkit-border-top-right-radius: 0px;
    -moz-border-radius-topleft: 0px;
    -moz-border-radius-topright: 0px;
    border-top-left-radius: 0px;
    border-top-right-radius: 0px;
}
.unround-bottom-corners{
    -webkit-border-bottom-left-radius: 0px;
    -webkit-border-bottom-right-radius: 0px;
    -moz-border-radius-bottomleft: 0px;
    -moz-border-radius-bottomright: 0px;
    border-bottom-left-radius: 0px;
    border-bottom-right-radius: 0px;
}

HTML

<button class="round-corners-5px unround-bottom-corners" style="background-color: white;"></button>
于 2012-07-14T12:27:42.957 回答
6

为此,border-radius css 标记有特定的变体:

border-top-left-radius:2em; 
border-top-right-radius:2em;
于 2012-07-14T12:26:55.320 回答
6

如果你只想圆某些角落,这是它的代码:

border-radius:5px 5px 5px 5px;

第一个值是左上角,第二个是右上角,第三个是左下角,第四个是右下角。

于 2012-07-14T12:46:56.683 回答
3

如果您使用 sass scss,那么您可以编写一次,然后将其作为简单的代码行重用,如下所示:

在你的 sass 或 scss 文件中,像这样定义 mixin:

@mixin rounded($amount: "10px",$position: null) {
  @if $position != null {
    @if $position == "top" or $position == "bottom" {
      //top or bottom
      -webkit-border-#{$position}-left-radius: $amount;
      -moz-border-#{$position}-left-radius: $amount;
      border-#{$position}-left-radius: $amount;

      -webkit-border-#{$position}-right-radius: $amount;
      -moz-border-#{$position}-right-radius: $amount;
      border-#{$position}-right-radius: $amount;

    } @else {
      // top-left or top-right or bottom-left or bottom-right
      -webkit-border-#{$position}-radius: $amount;
      -moz-border-#{$position}-radius: $amount;
      border-#{$position}-radius: $amount;      
    }
  } @else {
    // ALL IF EMPTY
    -webkit-border-radius: $amount;
    -moz-border-radius: $amount;
    border-radius: $amount; 
  }

}

然后在 scss 文件中,您可以像这样使用 mixin:

  @include rounded(); /*as default 10px on all corners*/
  @include rounded(15px); /*all corners*/ 

  @include rounded(15px, top); /*all top corners*/ 
  @include rounded(15px, bottom); /* all bottom corners*/ 

  @include rounded(15px, top-right); /*this corner only*/ 
  @include rounded(15px, top-left); /*this corner only*/ 
  @include rounded(15px, bottom-right); /*this corner only*/ 
  @include rounded(15px, bottom-left); /*this corner only*/  

此 .scss 代码将生成此 .css 代码:

 /*  as default 10px on all corners */
  -webkit-border-radius: "10px";
  -moz-border-radius: "10px";
  border-radius: "10px";


  /*  all corners  
  */
  -webkit-border-radius: 15px;
  -moz-border-radius: 15px;
  border-radius: 15px;


  /*  all top corners   
  */
  -webkit-border-top-left-radius: 15px;
  -moz-border-top-left-radius: 15px;
  border-top-left-radius: 15px;
  -webkit-border-top-right-radius: 15px;
  -moz-border-top-right-radius: 15px;
  border-top-right-radius: 15px;


  /*  all bottom corners   
  */
  -webkit-border-bottom-left-radius: 15px;
  -moz-border-bottom-left-radius: 15px;
  border-bottom-left-radius: 15px;
  -webkit-border-bottom-right-radius: 15px;
  -moz-border-bottom-right-radius: 15px;
  border-bottom-right-radius: 15px;


  /*  top-right corner only  
  */
  -webkit-border-top-right-radius: 15px;
  -moz-border-top-right-radius: 15px;
  border-top-right-radius: 15px;


  /*  top-left corner only  
  */
  -webkit-border-top-left-radius: 15px;
  -moz-border-top-left-radius: 15px;
  border-top-left-radius: 15px;


  /*  bottom-right corner only  
  */
  -webkit-border-bottom-right-radius: 15px;
  -moz-border-bottom-right-radius: 15px;
  border-bottom-right-radius: 15px;


  /*  bottom-left corner only   
  */
  -webkit-border-bottom-left-radius: 15px;
  -moz-border-bottom-left-radius: 15px;
  border-bottom-left-radius: 15px; } 
于 2013-12-08T06:42:53.757 回答
0

有助于理解它是如何工作的,我这样做是为了制作左方圆角和右圆角:

.btn-circle.btn-lg {
        width: 170px;
        height: 47px;
        padding: 10px 16px;
        font-size: 17px;
        line-height: 1.33;
        /*border-radius: 25px;*/ //use this for both side rounded corner side
        border-radius: 0px 50px 50px 0px / 50px 50px 50px 50px;
    }

指南帮助我在 twitter bootstrap 中制作圆形按钮

于 2015-02-28T11:43:54.113 回答