DEV Community

Cover image for CSS Battle: #12 - Wiggly Moustache
Jatin Sharma
Jatin Sharma

Posted on • Originally published at j471n.in

CSS Battle: #12 - Wiggly Moustache

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:
Wiggly Moustache

Solution

So now look at the Solution and how we are going to achieve this.

HTML

<p l>
<p m>  
<p r>  
<p d>  
Enter fullscreen mode Exit fullscreen mode
  • <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;
}
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.

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

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)

Collapse
 
gass profile image
Gass

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:

<section class='box'>
    <div class='semi-circle left'></div>
    <div class='semi-circle center'></div>
    <div class='semi-circle right'></div>
</section>
<div class='tip top-left'></div>
<div class='tip top-right'></div>
Enter fullscreen mode Exit fullscreen mode
body{
    margin:0;
    height:100vh;
    display:grid;
    place-items:center;
    background:#F5D6B4;
  }
  .box{
    width:300px;
    height:100px;
    display:flex;
  }
  .semi-circle{
    width:70px;
    height:35px;
    border-radius: 0 0 70px 70px;
    border:20px solid #D86F45;
    border-top:none;
  }
  .left{transform:translate(20px, 45px)}
  .center{transform:rotate(180deg)}
  .right{transform:translate(-20px, 45px)}
  .tip{
    position:absolute;
    top:138px;
    width:20px;
    height:10px;
    background:#D86F45;
    border-radius:20px 20px 0 0;
    border:2px solid #F5D6B4;
    border-bottom:none;
  }
  .top-left{left:68px}
  .top-right{right:68px}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
j471n profile image
Jatin Sharma

What's in?

in stands for inches (1in === 96px). Its an absolute CSS unit. You can learn more about that here

I hope your HTML and name classes would be more descriptive. It would be easier to read.

In this article, I have <p l> for left semi circle and l 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:

.left {
    /* Some Styles */
}
Enter fullscreen mode Exit fullscreen mode

CSS Battle allows you to directly use that by simply using brackets [] like this:

[left] {
    /* Some Styles */
}
Enter fullscreen mode Exit fullscreen mode

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.

For me it was hard to figure out how to make the rounded tips on the left and right.

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

.dot {
  width: 20px;
  height: 20px;
  background: #d86f45;
  border-radius: 1in;
  position: absolute;
  left: 70px;
  bottom: 124px;
  box-shadow: 240px 0 #d86f45;
}
Enter fullscreen mode Exit fullscreen mode

I recommend you to take a look at CSS Battle Tips & Tricks. So, you don't get lost in the future articles.