Get the App
SLTechnology News&Howtos  ›  Development  › 

How to create triangular background Image by css

Shulou Source: shulou.com Published: 2022-06-01 04:37:15 09月12日 Update

This article is about how css creates triangular background images. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

How to create a triangular background image

When we want to show some completely different choices (such as day and night or winter and summer).

This is done by creating two div for the entire viewport, then you need to add a background image to both of them, and then the second div requires a clip-path property to create triangles.

Body {margin: 0; padding: 0;} div {position: absolute; height: 100vh; width: 100vW;} .day {background-image: url ("https://images.unsplash.com/photo-1477959858617-67f85cf4f1df?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2613&q=80"); background-size: cover; background-repeat: no-repeat }. Night {background-image: url ("https://images.unsplash.com/photo-1493540447904-49763eecf55f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2250&q=80"); background-size: cover; background-repeat: no-repeat; clip-path: polygon (100vw 0,0% 0vh, 100vw 100vh);}

The clip-path property creates a crop region that sets which part of the element should be displayed. The part within the area shows that it is hidden outside the area.

Thank you for reading! This is the end of the article on "how to create triangular background images in css". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Image background triangle region two content attribute more article different good practical triangle element article look knowledge this is part night Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Linux vpn macOS NVidia