0

I would like to create div like this picture:

enter image description here

So far I created this:

<div style="width: 300px; height: 200px; left:20px; top: 40px;">
<div style="width: 300px; height: 20px; top: 0px; background-color: #76b900; border-radius: 3px; "/>

</div>

How I can add color gradient like the picture. And also how I can add 45 degree angle like the picture?

user1285928
  • 1,140
  • 26
  • 93
  • 143

4 Answers4

1

I think that you would need 2 divs to accomplish this using just css.

One as a block with the text and on the right side you should float a div and apply a similar style to this:

How do CSS triangles work?

I would personally consider images.

Community
  • 1
  • 1
thedev
  • 2,706
  • 8
  • 32
  • 47
1

You can either use 2 divs, or you can use an :after pseudo-element with an image of the arrow point alone.

EDIT: Come to think of it, using 2 skewed divs would also require you to use a :before pseudo-element with the image of the arrow point.

Jules
  • 13,775
  • 13
  • 51
  • 95
1

The idea is to use a pseudo element with the same gradient as the main element, but diagonally across, then rotate it 45 degrees:

h1 {
    background: linear-gradient(#5FA309, #3B8018);
    position: relative;
    line-height: 30px;
}

​h1:after {
    content: '';
    background: linear-gradient(top left, #5FA309, #3B8018);
    transform: rotate(45deg);
    position: absolute;
    top: 4px; right: -11px;
    width: 21px;
    height: 21px;
}​

Here's a demo: http://codepen.io/JosephSilber/pen/bFfqn

P.S. Don't forget vendor prefixes in production...

Joseph Silber
  • 205,539
  • 55
  • 352
  • 286
1

Here you go:

<div class-"container">
 <div class="arrow-body"></div>
 <div class="arrow-right"></div>
</div>

.container {
 width:300px;
 overflow:auto;
}

.arrow-body {
 width:270px;
 height:60px;
 background:green;
 float:left;
}

.arrow-right {
 width: 0; 
 height: 0; 
 border-top: 30px solid transparent;
 border-bottom: 30px solid transparent;
 border-left: 30px solid green;
 float:left;
}
Billy Moat
  • 20,300
  • 7
  • 43
  • 37
  • This wouldn't allow gradients, and could easily be accomplished with the two pseudo elements. No need for all that extra markup (unless you're still supporting IE6, in which case I feel *really* sorry for you). – Joseph Silber Nov 02 '12 at 14:52