DEV Community

Cover image for CSS Battle: #4 - Ups n Downs
Jatin Sharma
Jatin Sharma

Posted on • Originally published at j471n.in

CSS Battle: #4 - Ups n Downs

In this article, I will solve a Ups n Downs 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:
Ups n Downs

Solution

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

HTML

<p class="left"></p>
<p class="middle"></p>
<p class="right"></p>
Enter fullscreen mode Exit fullscreen mode

CSS

Now let's style the containers.

body {
  margin: 0;
  background: #62306d;
}
.middle,
.left,
.right {
  position: absolute;
  background: #f7ec7d;
  width: 100;
  height: 100;
  border-radius: 10rem 10rem 0 0;
  margin-top: 50;
}
.middle {
  left: 150;
}
.left,
.right {
  transform: rotate(180deg);
  bottom: 34;
}
.left {
  left: 50;
}
.right {
  right: 50;
}
Enter fullscreen mode Exit fullscreen mode

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 % 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 l></p>
<p m></p>
<p r></p>
Enter fullscreen mode Exit fullscreen mode

Here I am using <p> tag and inside them l stands for left, m stands for middle and r stands for right.

CSS

body{
  margin:0;
  background:#62306D;
}
p[m],p[l],p[r]{
  position:absolute;
  background:#F7EC7D;
  width:100;
  height:100;
  border-radius:10rem 10rem 0 0;
  margin-top:50;
}
p[m]{
  left:150;
}
p[l],p[r]{
  transform:rotate(180deg);
  bottom:34;
}
p[l]{
  left:50;
}
p[r]{
  right:50;
}
Enter fullscreen mode Exit fullscreen mode

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 (4)

Collapse
 
dj_zekz profile image
Ezequiel Gonzalez

I'm kinda proud of this one, I've been forcing myself to use flexbox, and I think I came out pretty good XD

<div class="flexbox">
  <div class="L"></div>
  <div class="M"></div>
  <div class="R"></div>
</div>
<style>
  body{
    background: #62306D;
  }
  .flexbox{
    display:flex;
    justify-content:center;
    align-items:flex-start;
    align-content:center;
    width:100%;
    height:100vh;
    position:relative;
    top:42; 
  }
  .L{
    width:100;
    height:100;
    position:relative;
    border-radius:0% 0% 50% 50%;
    background:#F7EC7D;   
  }
  .M{
    width:100;
    height:100;
    position:relative;
    border-radius:50% 50% 0 0;
    background:#F7EC7D;
  }
  .R{
    width:100;
    height:100;
    position:relative;
    border-radius:0% 0% 50% 50%;
    background:#F7EC7D;
  }
  .l,.r{
    position:relative;
    top:100; 
  }
</style>

Enter fullscreen mode Exit fullscreen mode

PS not sure how to post the CSS here, sorry...

Collapse
 
j471n profile image
Jatin Sharma

That's pretty cool too.

Collapse
 
gass profile image
Gass • Edited

Nice battle, it entretained me for a while. This is my solution:

<body>
  <section>
   <div></div>
   <div></div>
   <div></div>
   <div></div>
   <div></div>
   <div></div>
  </section>
</body>
Enter fullscreen mode Exit fullscreen mode
body{
  background-color:rebeccaPurple;
  height:100vh;
  display:flex;
  justify-content:center;
  align-items:center;
}
section{
  display:grid;
  grid-template-columns: auto auto auto;
  height:200px;
  width:300px;
}
div:nth-child(even){
  background-color:khaki;
  border-radius:0% 0% 50% 50%;
}
div:nth-child(2){
  transform:rotate(180deg);
}
Enter fullscreen mode Exit fullscreen mode

jsfiddle.net/Gass_snippets/3qoyz48...

Keep it up!

Collapse
 
j471n profile image
Jatin Sharma

That's also a great solution, keep doing it :)