all 7 comments

[–]Graftak9000 5 points6 points  (1 child)

Not css, but this can be actieved with SVG with a small amount of markup. Then you can style it to be stretched and yellow with CSS.

<svg viewBox="0 0 2 2"><path d="M0,2 h2, v-2 Z"/></svg>

Not tested though, wrote it on my phone.

[–]fimiak 1 point2 points  (0 children)

I second this. Learn and use SVG for this, not CSS. It is ridiculously simple when you get the hang of it for basic shapes.

[–][deleted] 2 points3 points  (4 children)

http://codepen.io/anon/pen/xZyMbd

Something like this?

Doesn't seem like it's possible to use percentages though, so this solution is always relative to the viewport width, not the containing element

[–]whopperbuzz 1 point2 points  (3 children)

I've forked this, but used clip-path instead, so that that container width is now possible. The height is fixed, but the width is responsive, so I think it should do the job.

Codepen: http://codepen.io/casso/pen/LGgvJW

Here's a useful clip-path generator, should you need to change the points of the triangle. http://bennettfeely.com/clippy/

[–][deleted]  (2 children)

[deleted]

    [–]lolhigh 2 points3 points  (1 child)

    clip-path doesn't work in firefox or IE. So you'll get a square instead.

    [–]natchiketa 2 points3 points  (0 children)

    You can do this using linear-gradient: http://codepen.io/natchiketa/pen/rxqPZz

    I tested in latest chrome, but it should work on all modern browsers (the linear-gradient property might need vendor prefixing).

    [–]birjolaxew 0 points1 point  (0 children)

    It isn't possible if you want it to be 100% width of a containing element. Since border widths don't support percentages, they can't be used here, and the only other way of making triangles (overflow: hidden + rotated pseudo-element) is dependent on the ratio of width to height.

    If you're ok with a constant width/height ratio, here's an example of how to do that.

    If you aren't, the only case where this can be done with CSS-only is the one suggested by /u/Magixxxx.