Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically create an arrow with a gradient

Tags:

css

How could one go about dynamically generating a shape like this in CSS3:

enter image description here

Ignore the borders, as the important aspects are:

- The gradient in the arrow body, and that the gradient lasts from the tip to the end of the arrow.
- The length of the square part will vary.

I tried the regular :after method of adding a triangle to the end of a div element, but I couldn’t get the gradient to span both the tip and the body properly.

Fiddle: http://jsfiddle.net/rtuY9/8/

like image 880
KMN Avatar asked Sep 13 '26 14:09

KMN


1 Answers

You can try something like this - DEMO

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

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

div:after {
    z-index: -1;
    content: "";
    display: block;
    position: absolute;
    left: -125px;
    top: -51px;
    margin: 100px;
    height: 100px;
    width: 100px;
    background: #c00;

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

    background: -webkit-linear-gradient(45deg, #1e5799 0%, #2989d8 50%, #ffffff 50%, #ffffff 100%);
    background:    -moz-linear-gradient(45deg, #1e5799 0%, #2989d8 50%, #ffffff 50%, #ffffff 100%);
}
like image 100
Zoltan Toth Avatar answered Sep 16 '26 08:09

Zoltan Toth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!