In this article, I will solve a Wiggly Moustache 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
<p l>
<p m>
<p r>
<p d>
-
<p l>
: For left Semicircle -
<p m>
: For Center Semicircle -
<p r>
: For Right Semicircle -
<p d>
: For Circular Dots
CSS
Now let's style the containers.
body {
margin: 0;
background: #f5d6b4;
}
p {
position: fixed;
}
[l], [m], [r] {
width: 60;
height: 30;
border: 20px solid #d86f45;
border-radius: 0 0 1in 1in;
border-top: 0;
bottom: 85;
}
[l] { left: 70 }
[r] { right: 70 }
[m] {
transform: scaleY(-1);
bottom: 135;
left: 150;
}
[d] {
width: 20;
height: 20;
background: #d86f45;
border-radius: 1in;
left: 70;
bottom: 124;
box-shadow: 240px 0 #d86f45;
}
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.
Minified Version:
<p l><p m><p r><p d><style>body{margin:0;background:#F5D6B4}p{position:fixed}[l],[m],[r]{width:60;height:30;border:20px solid #D86F45;border-radius:0 0 1in 1in;border-top:0;bottom:85}[l]{left:70}[r]{right:70}[m]{transform:scaleY(-1);bottom:135;left:150}[d]{width:20;height:20;background:#D86F45;border-radius:1in;left:70;bottom:124;box-shadow:240px 0 #D86F45}
Wrapping up
There are many ways to solve this. You can share your approach in the comments. 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)
Nice one. What's
in
? Your CSS is very short as usual. I hope your HTML and name classes would be more descriptive. It would be easier to read.For me it was hard to figure out how to make the rounded tips on the left and right.
This was my approach:
in
stands forinches
(1in === 96px
). Its an absolute CSS unit. You can learn more about that hereIn this article, I have
<p l>
for left semi circle andl
is the class in short form (you don't need to pass class attribute in CSS Battle). In normal CSS we style the CSS like this:CSS Battle allows you to directly use that by simply using brackets
[]
like this:In my code, I try to keep everything short to get higher score. My code will only work in CSS Battle as it uses some special keywords provided by CSS Battle. However, it will work in other browsers or Codepens after some alteration the code.
You can simply create a circular ball with the same width and height, then position it according to the container and then let the
box-shadow
do the magic. Following is the example (play with values):I recommend you to take a look at CSS Battle Tips & Tricks. So, you don't get lost in the future articles.