DEV Community

Cover image for CSS Battle #9 - Tesseract
Olzhas Askar
Olzhas Askar

Posted on

CSS Battle #9 - Tesseract

The difference between these Series and any from Netflix is that on Netflix you get all episodes at once.
In contrast, I will need to write mine first. One post every three days. At least, that is what I wanted in the beginning. Naïve me.


Did you know there was a CSS Battle Community? Well, in case you didn't, here it is. Try to guess which kind of posts are the most frequent? Missing just a bit to 100%. The struggle is real. Thus, the series. I hope it helps.

The Solution

I need to confess. I didn't manage this one. But I am optimistic. The best I can is good enough.
Let's start with body. We make it striped by using linear-gradient. The first and the last 25% take #222730 and the middle 50% gets #4CAAB3 as a background color. The groundwork is done.

body {
  background: linear-gradient(#222730 25%, #4caab3 25% 75%, #222730 75%);
}
Enter fullscreen mode Exit fullscreen mode

In the middle of the plot, we should have a rhombus. And inside, a circle. Let's mark them up. Note that you may use a p tag inside of a div instead of giving a generic division a kind of semantic meaning by attributing it with an id. After all, a paragraph is also a block element.

<div id="rhombus">
  <div id="circle"></div>
</div>
Enter fullscreen mode Exit fullscreen mode

When it comes to a rhombus, we make a square and give it a size of 150 x 150, nice background color and a border of 50px to make it look cut-out. Then we center it by one of the older methods, using a fixed positioning. Note, that here as well, we could use an absolute positioning relative to its parent, but since body is the parent, fixed will bring us to the same outcome with less hassle. Finally, we also rotate the square to become a rhombus.

#rhombus {
  width: 150px;
  height: 150px;
  background: #4caab3;
  border: 50px solid #222730;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(45deg);
}
Enter fullscreen mode Exit fullscreen mode

The last one is the circle. We position it using a margin of 50px. The rest is pretty straight-forward. Size, background, and border radius.

#circle {
  width: 50px;
  height: 50px;
  background: #393e46;
  border-radius: 50px;
  margin: 50px;
}
Enter fullscreen mode Exit fullscreen mode

This is the whole solution.

<div id="rhombus">
  <div id="circle"></div>
</div>

<style>
  body {
    background: linear-gradient(#222730 25%, #4CAAB3 25% 75%, #222730 75%);
  }
  #rhombus {
    width: 150px;
    height: 150px;
    background: #4CAAB3;
    border: 50px solid #222730;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(45deg);
  }
  #circle {
    width: 50px;
    height: 50px;
    background: #393E46;
    border-radius: 50px;
    margin: 50px;
  }
</style>
Enter fullscreen mode Exit fullscreen mode

At the time of writing this, and I must admit, I've given up already, I just wanted to search for the name of the term. How would you call this thin line? Apparently, it is called bleeding. And one of the search results was promising to fix the problem. I thought, why not? And you know what? It worked. So, in order to make the code to achieve a full match, just add background-clip: padding-box to the #rhombus. What is this padding-box?

Outtakes

This one is quite funny. The code above will not work in Firefox. In fact, it will look something like this.

Stripes

The very first, originally bleeding version will be like this.

White

And here comes the code. Keep in mind this is a non-polished version.

<div><p></p></div>

<style>
  body {
    margin: 0;
    position: relative;
    background: linear-gradient(#222730 25%, #4CAAB3 25% 75%, #222730 75%);
  }
  div {
    width: 150px;
    height: 150px;
    background: #4CAAB3;
    border: 50px solid #222730;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(45deg);
    background-clip: padding-box;
  }
  p {
    width: 50px;
    height: 50px;
    background: #393E46;
    border-radius: 50px;
    margin: 50px;
  }
</style>
Enter fullscreen mode Exit fullscreen mode

By the way, are you enjoying CSS Battle so far? The guys are putting in a lot of work. So, in case you wondered how you can support them, here you go:

I personally find it funny how a light theme is something PRO™
But jokes aside, there are some potentially game-changing features coming like targets created by the Community and own battles. Great stuff if you want to hire a frontend frontend developer or just want to brag about your minifying skills.

Top comments (8)

Collapse
 
nando123 profile image
Nancy Do

1 div solution:

<div></div>
<style>
  body {
    background: linear-gradient(
      #222730 25%, 
      #4CAAB3 25% 75%, 
      #222730 75%
    );
  }

  div {
    margin: 125px auto; 
    border-radius: 50%; 
    width: 50px;
    height: 50px;
    background: #393E46;
  }

  div::before {
    position: fixed; 
    content: "";
    background: #4CAAB3;
    z-index: -1;
    margin: -50px -50px;
    width: 150px; 
    height: 150px; 
    transform: rotate(45deg);
    box-shadow: 0 0 0 50px #222730; 
  }  

</style>
Enter fullscreen mode Exit fullscreen mode
Collapse
 
mshahanwaz profile image
Mohammad Shahanwaz

Doesn't work in Firefox!!

Collapse
 
idaomoumi profile image
idaomoumi

I wanted to try to write the code like battle #3 but there's a small problem that I cant find what I need to fix. There seems to be a blue border around my border.

<div id="a"></div>
<div id="b">
<div id="c">
<style>
  *{
    margin:0;
    background:#222730;
  } 

   #a {
     margin:75px 0 0 0;
    width: 400px;
    height: 150px;
    background: #4CAAB3;
     overflow: hidden;
     position:relative;
  }
  #b{
    width:150px;
    height:150px;
    background:#4CAAB3;
    position: fixed;
    border: 50px solid #222730;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%) rotate(45deg);
  }
  #c{
     border-radius: 25px;
    width: 50px;
    height: 50px;
    background: #393E46;
    margin: 50px auto;
  }
</style>

Enter fullscreen mode Exit fullscreen mode

Image description

Collapse
 
mshahanwaz profile image
Mohammad Shahanwaz

Just use backface-visibility: hidden; in #b selector

Collapse
 
idaomoumi profile image
idaomoumi

Although when I submit my code, it matches 100%. :))

Collapse
 
saddamcrr7 profile image
Hossain Saddam • Edited

Here is my code in non-polished version

body{
background: #222730;
margin: 0;
}
#right_angle{
width: 24;
height: 0;
border-style: solid;
border-width: 75px 75px 75px 0px;
border-color: #4CAAB3 transparent #4CAAB3;
margin-top: 75
}
#middle_rect{
width: 150px;
height: 150px;
background: #4CAAB3;
position: absolute;
top: 25%;
left: 125px;
transform: rotate(45deg)
}
#middle_rect::before{
content: '';
width: 50px;
height: 50px;
background: #393E46;
position: absolute;
margin: 50px;
border-radius: 50px
}
#left_angle{
width: 24;
height: 0;
border-style: solid;
border-width: 75px 75px 75px 0px;
border-color: #4CAAB3 transparent #4CAAB3;
position: absolute;
right: -1;
top: 75;
transform: rotate(180deg)
}

Collapse
 
chinchang profile image
Kushagra Gour

Thanks for the shout-out to CSSBattle PRO :)

Collapse
 
pheeria profile image
Olzhas Askar

Thanks for the new challenges :)