DEV Community

Cover image for CSS Battle: #7 - Leafy Trail
Jatin Sharma
Jatin Sharma

Posted on • Updated on

CSS Battle: #7 - Leafy Trail

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:
Leafy Trail

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

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;
}
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.

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 (9)

Collapse
 
lukeshiru profile image
Luke Shiru

This series is cool for code golf, but don't forget that more often than not, it would be a better solution to just use a SVG (which is a way better fit for logos, icons and the like). This one for example could just be:

<svg viewBox="0 0 10 6">
    <path fill="#1A4341" d="M3 6H0V4a4 4 0 0 1 4-4h2L3 6Z" />
    <path fill="#998235" d="M5 6H2V4a4 4 0 0 1 4-4h2L5 6Z" />
    <path fill="#F3AC3C" d="M4 6V4a4 4 0 0 1 4-4h2v2a4 4 0 0 1-4 4H4Z" />
</svg>
Enter fullscreen mode Exit fullscreen mode

No need for HTML+CSS for this kind of things. That SVG can be inlined or loaded with an img tag, or even on a canvas if you want. It will be responsive and way easier to make accessible.

Cheers!

Collapse
 
j471n profile image
Jatin Sharma • Edited

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 :)

Collapse
 
link2twenty profile image
Andrew Bone • Edited

So what we're saying is we need a html free solution?

Thread Thread
 
j471n profile image
Jatin Sharma • Edited

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.

Thread Thread
 
lukeshiru profile image
Luke Shiru
  1. For icons, logos and similar, is better to use SVG, so no discussion there, just facts. The "challenge" or "code golf" in this series of posts is HTML and CSS, so its ok. My comment was more like a "warning" for folks that might see this and think is a good idea for "real world" scenarios, when it isn't ^_^
  2. Andrew is joking with the CSS only solution based on your reply to my comment saying to only use CSS. He isn't being serious 🤣
Collapse
 
link2twenty profile image
Andrew Bone • Edited

Nice solution! You can use ::before and ::after to great effect with challenges like this.

Collapse
 
j471n profile image
Jatin Sharma

This approach is also a good one. However, I didn't use it because of the character count as before and after, increase the characters in the code.

Collapse
 
link2twenty profile image
Andrew Bone • Edited

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 😁

Thread Thread
 
j471n profile image
Jatin Sharma

Now this is cool, one of the best one.