Welcome to CSSBattle Challenges!
In this short article, I go through my solution for CSSBattle - #7 Leafy Trail challenge. Please refer to the code snippet below to get a better insight into my thought processes and the implementation detail.
Challenge:
Solution:
<div class="container">
<div class="leaf left"></div>
<div class="leaf center"></div>
<div class="leaf right"></div>
</div>
<style>
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
.container {
width: 100%;
height: 100%;
background: #0B2429;
position: relative;
}
.leaf {
width: 150px;
height: 150px;
border-top-left-radius: 100px;
border-bottom-right-radius: 100px;
position: absolute;
top: 50%;
left: 50%;
}
.left {
background: #1A4341;
transform: translate(calc(-50% + -50px), -50%)
}
.center {
background: #998235;
transform: translate(-50%, -50%)
}
.right {
background: #F3AC3C;
transform: translate(calc(-50% + 50px), -50%);
}
</style>
Key Takeaway(s):
- using
top: 50%
andleft: 50%
andtransform: translate(-50%, -50%)
to center absolute positioned elements- adjusting border radius properties to create a leaf like element
As always, I welcome any feedback or questions regarding the implementation detail of the challenge. Otherwise, I hope this was useful!
Top comments (0)