CSS3 polygons without images, how?

I am creating a website that looks something like this without expansion

The two structures at the top ae static and the four at the bottom are dynamic, when I speak dynamically, I mean extensibility, something like this

with expansion

Since these are just colors, shapes, and shadows, I believe you can use CSS3 to create them. But it's hard for me to do it. I even tried using CSSHat, but the result is terrible.

This is an example of a form. individual shape

This is the generated code:

width: 1920px; height: 341px; -moz-border-radius: 0 1920px 1920px / 0 181px 56px; -webkit-border-radius: 0 1920px 1920px / 0 181px 56px; border-radius: 0 1920px 1920px / 0 181px 56px; /* border radius */ -moz-background-clip: padding; -webkit-background-clip: padding-box; background-clip: padding-box; /* prevents bg color from leaking outside the border */ background-color: #3b0f1d; /* layer fill content */ 

And the result will look like this: converted shape A live example can be found here http://codepen.io/seraphzz/pen/mgDwd

What is the best way to achieve this?

+7
source share
4 answers

You can use CSS transforms to rotate the div.

I made the bottom divs dynamic and added some content to the div yellow and green .

 body { margin: 0; padding: 0; overflow-x: hidden; } .top, .top2, .yellow, .green, .bottom, .bottom2 { height: 200px; width: 140%; position: relative; left: -10%; transform-origin: 0% 100%; transition: 0.6s ease; } .top { top: -180px; background: #3C101D; transform: rotate(4deg); } .top2 { background: #931930; transform: rotate(-1.5deg); } .yellow { background: #F0810E; top: -200px; transform: rotate(0.6deg); } .content { display: block; width: 65%; position: relative; top: 10%; left: 10%; } .yellow .content { transform: rotate(-0.6deg); } .green { background: #425949; top: -320px; transform: rotate(-1.4deg); } .green .content { transform: rotate(1.4deg); } .bottom { background: #501B2B; top: -480px; transform: rotate(1.4deg); } .bottom2 { background: #3C101D; top: -600px; transform: rotate(-0.6deg); } .yellow:hover, .green:hover, .bottom:hover, .bottom2:hover { height: 400px; } 
 <div class="top"></div> <div class="top2"></div> <div class="yellow"> <div class="content">But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?</div> </div> <div class="green"> <div class="content">But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?</div> </div> </div> <div class="bottom"></div> <div class="bottom2"></div> 
+4
source

You can use CSS transformations (on :before / :after elements) to simulate effects.

Something like (demo at http://codepen.io/gpetrioli/pen/LHbIE )

 <div class="background"> <div class="shape"></div> </div> 

and

 background{background-color: #3c101d} .shape{ width: 800px; height: 341px; background: white; display: block; margin:10px; position:relative; overflow:hidden; } .shape:before{ content:''; width:110%; height:30px; background:#3c101d; position:absolute; height:100px; top:0; left:0; transform-origin:0 100%; transform: translateY(-100px) rotate(5deg); } .shape:after{ content:''; width:110%; height:30px; background:#3c101d; position:absolute; height:100px; bottom:0; left:0; transform-origin:0 0; transform: translateY(100px) rotate(-2deg); } 

notice: this code uses standard CSS properties. Add a provider prefixed if necessary

+1
source

Here is your solution for the "CSSHat form": -

 <!DOCTYPE html> <html> <body> <style> .background{ background-color: #3c101d; padding:22px 28px; display:inline-block; } .shape{ height: 30px; border-left: 645px solid white; border-top: 80px solid transparent; border-bottom: 40px solid transparent; } </style> <div class="background"> <div class="shape"></div> </div> </body> </html> 

The trick to getting all the shapes you want above is to play with: - all border sizes, all border colors and either the height or width of the div.

Codepen: - http://codepen.io/mrmoje/pen/EaQNOP

+1
source

These forms look like changing perspectives. http://css-tricks.com/almanac/properties/p/perspective/ I don’t believe there is a generator to go to extremes so that the left and right are wider than the parent with overflow hidden for the orange section 2- go schedule.

You can see from this generator the perspectives, as it rotates, that all angles are possible. http://desandro.imtqy.com/3dtransforms/examples/perspective-03.html

As an alternative markup instead of CSS3, which also does not require images

I would suggest using SVG to mark all polygons. It is much simpler and supported by all CSS3 browsers.

+1
source

All Articles