In this article, I will solve a Leafy Trail 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
<div class="leaf left"></div>
<div class="leaf middle"></div>
<div class="leaf right"></div>
CSS
Now let's style the leaves.
body{
margin: 0;
background: #0B2429;
display: grid;
place-items: center;
}
.leaf {
position: absolute;
width: 150;
height: 150;
border-radius: 100px 0;
}
.left {
z-index: 1;
background: #1A4341;
margin-left: -100;
}
.middle {
z-index: 2;
background: #998235;
}
.right{
z-index:3;
background: #F3AC3C;
margin-left: 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.
Codepen
Wrapping up
If you like this then don't forget to ā¤ļø it. And I'll see you in the next article. See you soon.
Top comments (7)
Nice solution! You can use
::before
and::after
to great effect with challenges like this.This approach is also a good one. However, I didn't use it because of the character count as
before
andafter,
increase the characters in the code.If lack of lines is what you want you can really shorten it down with box-shadow. Though that's the shortest I think I can go š
Now this is cool, one of the best one.
Totally agree, if you want to create logos and all just go with SVGs without hesitation. However in this challange we only use CSS to create a shape.
Peace :)
So what we're saying is we need a html free solution?
No, we can use HTML and CSS only. We don't need to use SVG because that's the different thing as there are various tools that allows you to create SVGs very easily. Only HTML and CSS.