html - Putting an image background onto a CSS Triangle -


i'm trying put background image on div using css borders create triangle. current efforts far. works fine solid colours, @ loss when comes images.

html

<div class="wrapper">   <div class="left triangle"></div>   <div class="right triangle"></div> </div> 

css

.wrapper {   padding:50px 0px;   height: 50px;   position: relative;   width: 300px;   background: url("http://4.bp.blogspot.com/-dq50t26bk1o/truhutyibwi/aaaaaaaanew/kknbq1lsgik/s1600/bokeh_texture04.jpg"); }  .triangle {   border-bottom: 50px solid #eee;   width: 50px;   position: absolute;   bottom: 0; }  .right {     right: 0;     border-left: 100px solid transparent; }  .left {     left: 0;     border-right: 100px solid transparent; } 

jsfiddle: http://jsfiddle.net/ars5g/9/

so, looking @ js fiddle, how make gray section image background of choice, rather having use colours such #111, #eee, etc..

a triangle in css hack, created displaying parts of border of element. therefore, triangle see not element itself, css border.

the border cannot styled using normal css background-image style, , start seeing limitations of css triangles, , why hack rather technique.

there css solution may work you: border-image.

border-image css style you'd expect; puts image border of element. since css triangle border, use put background image onto triangle.

however, things complicated. border-image style designed style borders, not triangles; has features styling corners , sides, , stretching images appropriately. haven't tried triangle, can predict may have quirks make tricky use. feel free give go.

the other problem border-image browser support. it's relatively new css style, , unsupported in many current browsers, including versions of ie. can see full browser support table @ caniuse.

because of these issues, suggest if want draw shapes in browser, should consider dropping css hacks, , using svg or canvas. these supported in browsers, , support drawing features possibly want.

css triangles great making occasional arrow shape, more complex it's lot easier use proper graphics rather trying pile more , more hacks css code.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -