Public Solving: Making a CSS art Christmas tree

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
No comments yet. Be the first to comment.
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

Today's puzzle is a bit different than anything we did before, as we are asked to hand over our version of a Christmas tree in CSS art.
You can find the complete puzzle here.
Coincidental I wrote a whole article on this approach last year, as there are many ways to achieve this. But all come with some pitfalls.
Read the article on creating tree Christmas threes in CSS
For this puzzle, I've decided to use the clip-path version. During my research last year, this was the cleanest and most versatile version.
To set it up we need the following divs:
<div class="xmas-tree">
<div class="shadow"></div>
<div class="layer"></div>
<div class="shadow"></div>
<div class="layer"></div>
<div class="layer"></div>
</div>
As you can see, there are three layers and two shadow layers.
As for the main wrapper I've decided to not recalculate the clip-paths but rather use a scale transform to make it a bit bigger:
.xmas-tree {
position: relative;
margin-top: 20px;
transform: scale(3, 3);
top: -250px;
left: -150px;
}
Note: this is the cheap way of doing it 😅 *(We should have opted to change the clip-paths)
Then the layer element will actually do most of the work to make a conic shape.
.xmas-tree .layer {
position: absolute;
width: 100px;
height: 100px;
border-radius: 50%;
background: green;
clip-path: polygon(50% 5%, 100% 85%, 100% 100%, 0 100%, 0 85%);
}
This works because it actually creates a square, this gets converted to a circle, and we cut a sphere out.

The shadow layer uses the same pattern, but we slightly offset the conic sphere.
.xmas-tree .shadow {
position: absolute;
width: 80px;
height: 80px;
border-radius: 50%;
background: black;
clip-path: polygon(50% 0%, 0% 110%, 95% 100%);
margin-top: 20px;
margin-left: 10px;
}
However, now all the layers are stacked on top of each other. So let's offset them all a bit.
.xmas-tree div:nth-child(1) {
transform: translateY(5px);
z-index: 3;
}
.xmas-tree div:nth-child(2) {
transform: translateY(0);
z-index: 3;
}
.xmas-tree div:nth-child(3) {
transform: translateY(40px);
z-index: 2;
}
.xmas-tree div:nth-child(4) {
transform: translateY(35px);
z-index: 2;
}
div:nth-child(5) {
transform: translateY(70px);
z-index: 1;
}
And for the cherry on top, let's add an emoji star to our tree.
.xmas-tree:before {
content: '⭐️';
position: absolute;
left: 42px;
z-index: 10;
top: -9px;
}
Resulting in the following:
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter