html - CSS apply gradient to right triangle shape with solid fill -
i want apply same gradient triangle (class="triangle-right") rectangle (class="fillblue"). have seen other examples not working me. combining both shapes , using single class awesome too!
css:
.fillblue { background: rgb(208,228,247); /* old browsers */ background: -moz-linear-gradient(top, rgba(208,228,247,1) 0%, rgba(115,177,231,1) 24%, rgba(10,119,213,1) 50%, rgba(83,159,225,1) 79%, rgba(135,188,234,1) 100%); /* ff3.6+ */ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(208,228,247,1)), color-stop(24%,rgba(115,177,231,1)), color-stop(50%,rgba(10,119,213,1)), color-stop(79%,rgba(83,159,225,1)), color-stop(100%,rgba(135,188,234,1))); /* chrome,safari4+ */ background: -webkit-linear-gradient(top, rgba(208,228,247,1) 0%,rgba(115,177,231,1) 24%,rgba(10,119,213,1) 50%,rgba(83,159,225,1) 79%,rgba(135,188,234,1) 100%); /* chrome10+,safari5.1+ */ background: -o-linear-gradient(top, rgba(208,228,247,1) 0%,rgba(115,177,231,1) 24%,rgba(10,119,213,1) 50%,rgba(83,159,225,1) 79%,rgba(135,188,234,1) 100%); /* opera 11.10+ */ background: -ms-linear-gradient(top, rgba(208,228,247,1) 0%,rgba(115,177,231,1) 24%,rgba(10,119,213,1) 50%,rgba(83,159,225,1) 79%,rgba(135,188,234,1) 100%); /* ie10+ */ background: linear-gradient(to bottom, rgba(208,228,247,1) 0%,rgba(115,177,231,1) 24%,rgba(10,119,213,1) 50%,rgba(83,159,225,1) 79%,rgba(135,188,234,1) 100%); /* w3c */ filter: progid:dximagetransform.microsoft.gradient( startcolorstr='#d0e4f7', endcolorstr='#87bcea',gradienttype=0 ); /* ie6-9 */ height: 40px; width: 100px; display: inline-block; float: left; color: white; text-align: center; line-height: 40px; font-weight: bold; } .triangle-right { width: 0; height: 0; border-top: 20px solid transparent; border-left: 40px solid lightblue; border-bottom: 20px solid transparent; float: left; }
html:
<div class="fillblue">step 1</div><div class="triangle-right"></div>
part 1: giving triangle gradient
the easiest way achieve invert triangle. , extend length of element gradient.
jsfiddle demo.
inverting triangle
rather giving border-left
on triangle solid colour, want give top , bototm borders colour (in case want match background colour, lets make these white that's jsfiddle background colour):
.triangle-right { ... border-top: 20px solid white; border-left: 40px solid transparent; border-bottom: 20px solid white; }
if you're unsure achieves, here example of triangle when top , bottom borders set red
instead of white
:
increasing width of gradient element
as triangle 40px wide, need increase width of our gradient element 40px. i've used padding ensure text remains in same place:
.fillblue { ... padding-right: 40px; }
with same red triangle used above, looks like:
positioning inverted triangle on top of our gradient element
now need set negative margin on our inverted triangle make appear on top of our gradient element:
.triangle-right { ... margin-left: -40px; }
finally, using red triangle again, our finished result looks this:
part 2: combining both shapes 1 element
to can make use of :after
pseudo-element.
jsfiddle demo.
first off, lets modify our html:
<div class="fillblue">step 1</div>
now lets give our .fillblue
element relative positioning. can absolutely position our triangle in next step:
.fillblue { ... position: relative; }
now modify our previous .triangle-right
styling use :after
pseudo-element instead:
.fillblue:after { width: 0; height: 0; border-top: 20px solid white; border-left: 40px solid transparent; border-bottom: 20px solid white; }
finally give new properties position correctly , make display:
.fillblue:after { ... content: ''; position: absolute; top: 0; right: 0; }
Comments
Post a Comment