In this article, I will solve a Totally Triangle CSS Challenge on CSS Battle. Let's look at the problem first.
Problem
We need to create the following container by using CSS Properties only:
Solution
So now look at the Solution and how we are going to achieve this.
HTML
<p>
CSS
Now let's style the containers.
* {
margin: 0;
background: #0b2429;
}
p {
position: fixed;
width: 200;
height: 200;
background: #f3ac3c;
transform: rotate(45deg);
left: -100;
top: -100;
}
Note: In CSS Battle you can use
100
instead of100px
. You don't need to definepx
in CSS. However, if you are usingrem
or%
, you need to pass them separately. That's why in the above CSS code there are no units mostly. For more info visit hereMinify the code or CSS by using any CSS Minifier. It helps you to reduce the characters in the code which will increase the score.
Minified Version:
<p><style>*{margin:0;background:#0B2429}p{position:fixed;width:200;height:200;background:#F3AC3C;transform:rotate(45deg);left:-100;top:-100}
Alternative Method
CSS
body {
background: linear-gradient(135deg, #f3ac3c 100px, #0b2429 100px);
}
You can achieve this by using linear-gradient()
also which is a lot simpler. You don't even need HTML in this.
Wrapping up
There are many ways to solve this. You can share your approach in the comments. If you like this then don't forget to ❤️ it. And I'll see you in the next article. See you soon.
Top comments (2)
These are impressive solutions. To be honest I couldn't figure it out by my own. I had to pick at your solutions. But I came up with the following:
I didn't think about using
translate
. Nice Solution :)