3

箭

嗨,我正在为这个挠头。我想创建一个如图所示的 CSS 渐变箭头,并且能够将红色部分的填充定义为百分比。红色块只是纯色。

从这个JFiddle示例中,我在创建绿色箭头方面取得了一些进展,但三角形上的渐变方向错误。我仍然不确定如何让红色块填充绿色箭头的百分比。例如,如果红色部分是 90%,我将不得不以某种方式创建半个三角形。请帮忙 :)

绿色箭头的示例代码:

div.a3 {
   width: 100px;
   height: 50px;
   position: relative;
   margin: 50px;

   background: -webkit-linear-gradient(top, #99c739 0%,#4eb739 100%);
   background:    -moz-linear-gradient(top, #99c739 0%, #4eb739 100%); 
}

div.a3:after {
   z-index: -1;
   content: "";
   display: block;
   position: absolute;
   right: -75px;
   top: -50px;
   margin: 50px;
   height: 50px;
   width: 50px;

   -webkit-transform:rotate( -45deg );
   -moz-transform:rotate( -45deg );
        transform:rotate( -45deg );

   background: -webkit-linear-gradient(135deg, #99c739 0%, #4eb739 50%, #ffffff 50%, #ffffff 100%);
   background:    -moz-linear-gradient(135deg, #99c739 0%, #4eb739 50%, #ffffff 50%, #ffffff 100%);
}
4

2 回答 2

1
div{
    width: 200px;
    height: 100px;
    margin: 50px 0;
    position:relative;
    background: #d72200;
    background: -moz-linear-gradient(left,  #d72200 0%, #d72200 20%, #9ac739 20%, #6bbe39 100%);
    background: -webkit-gradient(linear, left top, right top, color-stop(0%,#d72200), color-stop(20%,#d72200), color-stop(20%,#9ac739), color-stop(100%,#6bbe39));
    background: -webkit-linear-gradient(left,  #d72200 0%,#d72200 20%,#9ac739 20%,#6bbe39 100%);
    background: -o-linear-gradient(left,  #d72200 0%,#d72200 20%,#9ac739 20%,#6bbe39 100%);
    background: -ms-linear-gradient(left,  #d72200 0%,#d72200 20%,#9ac739 20%,#6bbe39 100%);
    background: linear-gradient(to right,  #d72200 0%,#d72200 20%,#9ac739 20%,#6bbe39 100%);
}
div:after{
    content:'';
    width: 100px;
    height: 100px;
    position: absolute;
    left: 100%;
    top: 0;
    background: #4eb739;
    background: -moz-linear-gradient(45deg,  #4eb739 0%, #6bbe39 50%, #6bbe39 100%);
    background: -webkit-gradient(linear, left bottom, right top, color-stop(0%,#4eb739), color-stop(50%,#6bbe39), color-stop(100%,#6bbe39));
    background: -webkit-linear-gradient(45deg,  #4eb739 0%,#6bbe39 50%,#6bbe39 100%);
    background: -o-linear-gradient(45deg,  #4eb739 0%,#6bbe39 50%,#6bbe39 100%);
    background: -ms-linear-gradient(45deg,  #4eb739 0%,#6bbe39 50%,#6bbe39 100%);
    background: linear-gradient(45deg,  #4eb739 0%,#6bbe39 50%,#6bbe39 100%);
    -moz-transform: scale(1) rotate(45deg) translate(0px, 0px) skew(0deg, 0deg);
    -webkit-transform: scale(1) rotate(45deg) translate(0px, 0px) skew(0deg, 0deg);
    -o-transform: scale(1) rotate(45deg) translate(0px, 0px) skew(0deg, 0deg);
    -ms-transform: scale(1) rotate(45deg) translate(0px, 0px) skew(0deg, 0deg);
    transform: scale(1) rotate(45deg) translate(0px, 0px) skew(0deg, 0deg);
    z-index: -2;
    margin: 0 0 0 -50px;
}
div:before{
    content:'';
    position:absolute;
    top: 0;
    right: 0;
    height: 100%;
    padding: 22px 0;
    z-index: -1;
    background: #fff;
    margin: -22px 0;
    width: 100%;
}
于 2013-08-05T13:25:06.933 回答
0

下面的代码似乎创建了一个箭头。

是你要找的吗?

    div.a3 {
    width: 100px;
    height: 50px;
    position: relative;
    margin: 50px;

    background: -webkit-linear-gradient(left, #1e5799 0%,#2989d8 100%);
    background:    -moz-linear-gradient(left, #1e5799 0%, #2989d8 100%); 
}

div.a3:after {
    z-index: -1;
    content: "";
    display: block;
    position: absolute;
    right: -75px;
    top: -50px;
    margin: 50px;
    height: 50px;
    width: 50px;
    background: #000;  
            transform:rotate( -45deg );

    background: -webkit-linear-gradient(135deg, #1e5799 0%, #2989d8 50%, #ffffff 50%, #ffffff 100%);
    background:    -moz-linear-gradient(135deg, #1e5799 0%, #2989d8 50%, #ffffff 50%, #ffffff 100%);
}
于 2013-08-05T12:57:08.357 回答