CSS Battle: #3 - Push Button

Jun 26, 2022
2 min read
380 words

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

index.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.

styles.css

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
}

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

index.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

styles.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.

Jatin's Newsletter

I write monthly Tech, Web Development and chrome extension that will improve your productivity. Trust me, I won't spam you.

Share on Social Media: