有关如何创建此按钮形状的建议

时间:2013-11-05 12:40:15

标签: css css3 css-shapes

我想创建一个按钮,两侧有两个轻微的翅膀,但不完全确定如何实现这种形状,并想知道是否有人可以提供一些指导?

enter image description here

我明白我需要使用之前和之后的伪装,但不确定如何创建进入按钮主体的轻微曲线?

4 个答案:

答案 0 :(得分:2)

取自this site here.

您可以使用以下方法创建形状:

#trapezoid {
    border-bottom: 100px solid red;
    border-left: 50px solid transparent;
    border-right: 50px solid transparent;
    height: 0;
    width: 100px;
}

Here is an example

如果你想要文字,把文字放在div中并添加到css:

text-align:center;
line-height:30px; /*Size of bottom border*/

然而,你需要做一些摆弄才能使它达到正确的宽度和高度等。

更新示例

答案 1 :(得分:2)

为了给人一种旋转远离POV的3D平面的印象,例如Star Wars opening crawls(重新创建in svg too),请使用(前缀)perspectiverotate3d(或rotateX)

要防止锯齿,请使用1px透明轮廓as described here

Running example

#trapezoid {
    -webkit-transform : perspective(400px) rotate3d(1, 0, 0, 20deg);
       -moz-transform : perspective(400px) rotate3d(1, 0, 0, 20deg);
         -o-transform : perspective(400px) rotate3d(1, 0, 0, 20deg);
        -ms-transform : perspective(400px) rotate3d(1, 0, 0, 20deg);
            transform : perspective(400px) rotate3d(1, 0, 0, 20deg);

        border-radius : 5px 5px 0 0;
              outline : 1px solid transparent;
}

如果您不希望旋转文本,请将上面的代码应用于::before伪元素,该元素相对于其父元素绝对定位:

Running example with non rotated text

代码:

#trapezoid {    
         width : 200px;
        height : 50px;
        margin : 10px;
       padding : 10px;
      position : relative;
    text-align : center;
}

#trapezoid::before {
    -webkit-transform : perspective(400px) rotate3d(1, 0, 0, 20deg);
       -moz-transform : perspective(400px) rotate3d(1, 0, 0, 20deg);
         -o-transform : perspective(400px) rotate3d(1, 0, 0, 20deg);
        -ms-transform : perspective(400px) rotate3d(1, 0, 0, 20deg);
            transform : perspective(400px) rotate3d(1, 0, 0, 20deg);
              outline : 1px solid transparent;
        border-radius : 5px 5px 0 0;
             position : absolute;
                  top : 0;
               bottom : 0;
                 left : 0;
                right : 0;
              content : '';
              z-index : -1;
           background : red;
}

答案 2 :(得分:1)

您可以使用:before:after来实现该风格。诀窍是歪斜侧面的元素并应用一个小的边界半径来进行平滑的舍入,如下所示:

button {
  border: 0 none;
  background-color: red;
  position: relative;

  font-size: 4em;
  margin-left: 100px; 
}

button:before,
button:after {
  content: '';
  position: absolute;
  background-color: inherit;
  top: 0;
  bottom: 0;
  width: 1em;
  z-index: -1;
}

button:before {
  left: -0.5em;
  -webkit-transform: skew(-10deg);
  transform: skew(-10deg);
  border-top-left-radius: 10%;
}

button:after {
  left: auto;
  right: -0.5em;
  -webkit-transform: skew(10deg);
  transform: skew(10deg);
  border-top-right-radius: 10%;
}

在这里小提琴:http://jsfiddle.net/JyhwZ/1/

答案 3 :(得分:1)

LIVE DEMO

enter image description here

  <ul>
    <li><a href="#" class="active">HOME</a></li>
    <li><a href="#">ABOUT</a></li>
    <li><a href="#">CONTACT</a></li>
  </ul>

ul{
  list-style:none;
  border-bottom:2px solid #000;
  overflow:auto;
}
ul li a{
  color:#fff;
  float:left;
  border-bottom: 30px solid #EC2327;
  border-left:   4px solid transparent;
  border-right:  4px solid transparent;
  border-top:    4px solid #EC2327;
  border-radius: 14px 14px 0 0;
  height: 0;
  padding:0 20px;
  line-height:30px;
  text-align:center;
  text-decoration:none;
}
a.active{
  border-bottom-color: #000;
  border-top-color:    #000;
}
相关问题