In this article, I will solve a Push Button 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="box"></div>
<div class="circle"></div>
It contains two div
one for the box and the other for circle.
CSS
Now let's style the containers.
body {
margin: 0;
background: #6592CF
}
.box {
background: #243D83;
width: 300;
height: 150;
transform: translate(50px, 50%)
}
.circle {
position: absolute;
transform: translate(75px, -50%);
background: #243D83;
width: 150;
height: 150;
border: 50px solid #6592CF;
border-radius: 999px
}
.circle::before {
position: absolute;
content: "";
border-radius: 10rem;
inset: 50px;
width: 50;
height: 50;
background: #EEB850
}
Note: In CSS Battle you can use
100
instead of100px
. You don't need to definepx
in CSS. However, if you are usingrem
or%
then you need to pass them separately. That's why in the above CSS code there are no units mostly. For more info visit here
Codepen
Alternate Solution
There could be many Alternative Solution I've used this one because of the less characters and simplicity.
HTML
<p b></p>
<p c></p>
Here I am using <p>
tag and inside them b
stands for box and c
stands for circle.
CSS
body {
margin: 0;
background: #6592CF
}
p[b] {
background: #243D83;
width: 300;
height: 150;
transform: translate(50px, 50%)
}
p[c] {
position: absolute;
transform: translate(75px, -63%);
background: #243D83;
width: 150;
height: 150;
border: 50px solid #6592CF;
border-radius: 999px
}
p[c]::before {
position: absolute;
content: "";
border-radius: 10rem;
inset: 50px;
width: 50;
height: 50;
background: #EEB850
}
Tip
Minify the code or CSS by using any CSS Minifier. It helps you to reduce the characters in the code that will increase score.
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 (2)
I prefer your first solution. Well done. I would appreciate if you could add more detailed explanations to the CSS properties on your future battles โ๏ธ
I'll keep that in mind, thanks for the feedback mate :)