Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
How to achieve diagonal containers in CSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Markshall" data-source="post: 404900" data-attributes="member: 1872"><p>Hiiiii</p><p></p><p>There's a nice looking trend that's been going on for a while now on websites, and that's the effect of diagonal containers where the container looks slanted, but the content inside looks normal.</p><p></p><p>It's actually really easy to achieve. Most people use really long SVGs to apply as a background or :before,:after pseudo elements to the containers to get the effect, but I'm going to show you a much easier way, and when put to real usage can look even better than this example <img src="/styles/default/xenforo/smilies/emojione/biggrin.png" class="smilie" loading="lazy" alt=":D" title="Big Grin :D" data-shortname=":D" /></p><p></p><p>Basically, all you have to do is skew/rotate your content container, then have another div inside that container which holds the content and skew/rotate it to the negative values of your content container.</p><p></p><p>The only thing is that you'll need to apply quite a high padding-bottom to your main container to make up for the loss made when skewing the container up.</p><p></p><p>[CODE]<!DOCTYPE html></p><p><html lang="en"></p><p> <head></p><p> <meta charset="UTF-8"></p><p> <title>Diagonal Containers</title></p><p></p><p> <style></p><p> body {</p><p> background-color: #efefef;</p><p> font: 400 14px/1.6 'Helvetica Neue', Helvetica, Arial, sans-serif;</p><p> color: #212121;</p><p> margin: 0;</p><p> padding: 0;</p><p> }</p><p> </p><p> .container {</p><p> max-width: 960px;</p><p> margin: 0 auto;</p><p> }</p><p> </p><p> header {</p><p> text-align: center;</p><p> padding: 30px 0;</p><p> border-bottom: 1px dashed #090909;</p><p> }</p><p> </p><p> header h1 {</p><p> margin: 10px 0;</p><p> }</p><p> </p><p> header h4 {</p><p> margin: 0;</p><p> }</p><p> </p><p> section {</p><p> margin: 100px 0;</p><p> background-color: #fff;</p><p> padding: 15px 30px;</p><p> padding-bottom: 60px;</p><p> transform: skew(5deg) rotateZ(2deg); /* skew the main container */</p><p> }</p><p> </p><p> .section-content {</p><p> transform: skew(-5deg) rotateZ(-2deg); /* now skew it back, negative of your main container */</p><p> }</p><p> </style></p><p> </head></p><p> </p><p> <body></p><p> <div class="container"></p><p> <header></p><p> <h1>Hello World</h1></p><p> <h4>Here's just a small tagline.</h4></p><p> </header></p><p> </p><p> <main></p><p> <section class="features"></p><p> <div class="section-content"></p><p> <h2>Features</h2></p><p> <p>Here are some perks of using this service...</p></p><p> <ul></p><p> <li>Perk #1</li></p><p> <li>Perk #2</li></p><p> <li>Perk #3</li></p><p> <li>Perk #4</li></p><p> </ul></p><p> </div></p><p> </section></p><p> </p><p> <section class="pricing"></p><p> <div class="section-content"></p><p> <h2>Pricing</h2></p><p> <p>Here are our pricing options</p></p><p> <ul></p><p> <li>Free: £0 p/m</li></p><p> <li>Basic: £5.49 p/m</li></p><p> <li>Advanced: £15.49 p/m</li></p><p> </ul></p><p> </div></p><p> </section></p><p> </main></p><p> </div></p><p> </body></p><p></html>[/CODE]</p><p></p><p>I've made a pen so you can see an example:</p><p><a href="http://codepen.io/anon/pen/bqjxqd" target="_blank">http://codepen.io/anon/pen/bqjxqd</a></p><p></p><p>Hope it helps if you choose to use it <img src="/styles/default/xenforo/smilies/emojione/biggrin.png" class="smilie" loading="lazy" alt=":D" title="Big Grin :D" data-shortname=":D" /></p></blockquote><p></p>
[QUOTE="Markshall, post: 404900, member: 1872"] Hiiiii There's a nice looking trend that's been going on for a while now on websites, and that's the effect of diagonal containers where the container looks slanted, but the content inside looks normal. It's actually really easy to achieve. Most people use really long SVGs to apply as a background or :before,:after pseudo elements to the containers to get the effect, but I'm going to show you a much easier way, and when put to real usage can look even better than this example :D Basically, all you have to do is skew/rotate your content container, then have another div inside that container which holds the content and skew/rotate it to the negative values of your content container. The only thing is that you'll need to apply quite a high padding-bottom to your main container to make up for the loss made when skewing the container up. [CODE]<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Diagonal Containers</title> <style> body { background-color: #efefef; font: 400 14px/1.6 'Helvetica Neue', Helvetica, Arial, sans-serif; color: #212121; margin: 0; padding: 0; } .container { max-width: 960px; margin: 0 auto; } header { text-align: center; padding: 30px 0; border-bottom: 1px dashed #090909; } header h1 { margin: 10px 0; } header h4 { margin: 0; } section { margin: 100px 0; background-color: #fff; padding: 15px 30px; padding-bottom: 60px; transform: skew(5deg) rotateZ(2deg); /* skew the main container */ } .section-content { transform: skew(-5deg) rotateZ(-2deg); /* now skew it back, negative of your main container */ } </style> </head> <body> <div class="container"> <header> <h1>Hello World</h1> <h4>Here's just a small tagline.</h4> </header> <main> <section class="features"> <div class="section-content"> <h2>Features</h2> <p>Here are some perks of using this service...</p> <ul> <li>Perk #1</li> <li>Perk #2</li> <li>Perk #3</li> <li>Perk #4</li> </ul> </div> </section> <section class="pricing"> <div class="section-content"> <h2>Pricing</h2> <p>Here are our pricing options</p> <ul> <li>Free: £0 p/m</li> <li>Basic: £5.49 p/m</li> <li>Advanced: £15.49 p/m</li> </ul> </div> </section> </main> </div> </body> </html>[/CODE] I've made a pen so you can see an example: [URL]http://codepen.io/anon/pen/bqjxqd[/URL] Hope it helps if you choose to use it :D [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
How to achieve diagonal containers in CSS
Top