DEV Community

Cover image for CSS Battle: #13 - Totally Triangle
Jatin Sharma
Jatin Sharma

Posted on • Originally published at j471n.in

CSS Battle: #13 - Totally Triangle

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:
Totally Triangle

Solution

So now look at the Solution and how we are going to achieve this.

HTML

<p> 
Enter fullscreen mode Exit fullscreen mode

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;
}
Enter fullscreen mode Exit fullscreen mode

Note: In CSS Battle you can use 100 instead of 100px. You don't need to define px in CSS. However, if you are using rem or %, you need to pass them separately. That's why in the above CSS code there are no units mostly. For more info visit here

Minify 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}
Enter fullscreen mode Exit fullscreen mode

Alternative Method

CSS

body {
  background: linear-gradient(135deg, #f3ac3c 100px, #0b2429 100px);
}
Enter fullscreen mode Exit fullscreen mode

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)

Collapse
 
gass profile image
Gass • Edited

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:

<div></div>
Enter fullscreen mode Exit fullscreen mode
  body{
    background:#0B2429;
  }
  div {
    width: 200px;
    height: 200px;
    background: #F3AC3C;
    transform: rotate(45deg) translate(-153px);
  }
Enter fullscreen mode Exit fullscreen mode
Collapse
 
j471n profile image
Jatin Sharma

I didn't think about using translate. Nice Solution :)