CSS Battle: #3 - Push Button

Jatin Sharma - Jun 27 '22 - - Dev Community

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:
Simply Square

Solution

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

HTML

<div class="box"></div>
<div class="circle"></div>
Enter fullscreen mode Exit fullscreen mode

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

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

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.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .