You can achieve this (albeit somewhat inaccurately) with CSS conversion:
Demo: http://jsfiddle.net/cUWm2/2/
<div class="shape"> A variable amount of content. </div>
.shape { position: relative; } .shape:before { content:""; -moz-transform: skewX(10deg); -webkit-transform: skewX(10deg); transform: skewX(10deg); width: 140%; left: -20%; height: 100%; background-color: #555; position: absolute; top: 0; z-index: -1; }
This provides the required form with minimal markup and decent (IE9 + and all other modern) browser support. However, when scaling the height up or down, eventually the triangles cease to be triangles, and the fourth edge becomes visible. You have several options:
- Find sizes that work for a practical amount of content and code.
- Dynamically change the amount of skew using JavaScript.
- Mix the background of the shapes with the main shape.
- Ignore it (depending on the layout, this does not necessarily look bad).
All that said (after playing with various CSS options), I will probably first consider an image-oriented solution. You can use the :before and :after pseudo-elements to create containers that resize vertically along with the main content, while maintaining the same width. You can then use the background image to cover the desired area or place a 100% x 100% image in the container.
source share