I need to create a box with a diagonal edge. Below is the picture and here is a link to it.
How would I do this using only CSS and HTML?
I'm aware its possible to create triangles in CSS, so maybe I create one div with the rounded corners for the 'yellow' portion of the box. Not sure how to do the inside grey part though.
I'd like to avoid the multiple images solution because this will be on mobile so that it loads as quickly as possible.
I'm looking into a solution with 3 divs inside and one being a triangle, I found a triangle maker here, then maybe relative position on the yellow div, and absolute position the content after that?
Why don't you just create an image and use that as the background. You could make the image look exactly like the gray and yellow above and then just add it to your "box".
here is the link to a js fiddle I have mocked up - this works pretty well, though I didn't do the entire style https://jsfiddle.net/6pcrneat/
Edit: I'll get back to you on the rounded corner of the triangle; I didn't notice that initially
There is a way to achieve this shape without having to use extra elements also. I can understand the reluctance in using multiple images but this approach only makes use of multiple backgrounds and should not have any impact on page load time.
In this approach, we create a
linear-gradient
background of a smaller size and position it at theright top
of the container to achieve the triangle effect.This approach can also be used with media queries without much issues.
HTML:
CSS
WORKING DEMO
Update:
Media query to 320x480:
Result: