I was working on something in photoshop. You can see the picture here:
The three triangles in the background refer to 3 different pages on my website. I was wondering if it was possible to put the images like this in CSS because I want them to work like links and put some simple zoom animation on it when you hover on it. I’m actually pretty noob and new to CSS in overall so this will be hard to make without doing a lot of research but I hope you guys can help me out and give me a way to start. Any help is appreciated, thanks a lot!
just to be clear, the 3 triangles should become 3 individual pictures. I’m forced to work with flexbox on school if that matters. Thanks again.
4
Answers
You can convert the image (or single elements) in base64 with a tool like this: https://www.base64-image.de/
It is one of the oldest ways to encode things into html (first proposed in 1987!). It is a way of turning different types of data into a series of letters and numbers that is safe for HTML. One of those data types is images.
I can’t paste a sample code here because it’s too long.
You can create a div container which will contain the image of the background background and then you just add div you position inside thanks to the position: absolute; using the top, bottom, right, left.
Like this :
So here is a rough draft of how I would create this in CSS. Basically I made three squares (
.triangle
to.triangle3
), gave them a rotation (transform: rotate(45deg);
) and added a gradient with a transparency (background-image: linear-gradient( to top left, red, transparent 50%);
) to each of the squares. This creates the basic triangular shape, as the other halves of the squares are hidden if they are big enough to go over the viewport. I positioned the elements next to each other by usingposition: absolute;
.I did not use flexbox however, but I don’t think flexbox would be the right thing to use in this case.
Another thing to point out: If you don’t want the 45° angles you can also use
transform:skew
. It skews the element and gives you the possibility to create different angles. This is a good resource for this.You can play with gradient, shadow and mix-blend-mode , but the best and most efficient is SVG.
example to start with if you feel like spending hours drawing your shapes .