I need to create a website with slanted div elements that must meet the following criteria:
- The sections should have a height of approximately 400px when displayed side by side, and about 800px when they stack vertically. It would be ideal if this could adjust automatically based on the content inside.
- They must be angled downwards at a fixed 7-degree angle.
- Full width of the screen.
- Should support an image background in addition to solid colors.
Example:
https://i.sstatic.net/DaNBY.png
Here's the code snippet I've tried so far:
.centeredContent{
transform: rotate(7deg) translateY(-50%);
-ms-transform: rotate(7deg) translateY(-50%);
-webkit-transform: rotate(7deg) translateY(-50%);
top:46%;
position:absolute;
background-color:rgba(120,0,0,.0)
}
.rotateBack {
-ms-transform: rotate(-7deg); /* IE 9 */
-webkit-transform: rotate(-7deg); /* Safari */
transform: rotate(-7deg);
background-color:rgba(0,120,0,.0)
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div id="div1" style="background-color:rgba(77,77,77,.2); position:relative;overflow:hidden;">
<div id="content1" class="centeredContent">
<div class="row" >
<div class="col-lg-offset-1 col-md-4 rotateBack">
<h2 style="color:#8aada8">topic 1</h2>
<p>Lorem...</p>
<button style="width:185px;height:52px;">Learn More</button>
</div>
<div class="col-lg-offset-2 col-md-4 rotateBack">
<h2 style="color:#8aada8">topic 2</h2>
<p>Lorem ...</p>
<button style="width:185px;height:52px;">Learn More</button>
</div>
</div>
</div>
<div style="background-color:rgba(0,0,100,.0);overflow:hidden">
<svg width="100%" id="svg1" style="margin:0;padding:0px;" viewBox="0 0 1590 600">
<polygon id="polygon1" points="0,0 0,400 1590,600 1590,200" style="fill:#525252;stroke:#525252;stroke-width:0" />
</svg>
</div>
</div>
However, I'm facing an issue where the gray bar doesn't adjust properly to the content size. Any suggestions on how to fix this?