Is it possible to make CSS an infinity symbol with one circle passing through another?

Asked

Viewed 318 times

7

I’m trying to make this way. Notice how one circle seems to pass inside the other...

inserir a descrição da imagem aqui

However I am not able to make an element "go through the other" with CSS, is it possible to arrive in this form only CSS? Like two intertwined bows?

Go as far as I can go.

.box {
  width: 200px;
  height: 200px;
  box-sizing: border-box;
  position: absolute;
  border-radius: 50%;
  border: 20px solid tomato;
  box-shadow: 0 0 15px 0 rgba(0, 0, 0, .75);
}
.box.y {
  left: 100px;
} 
<div class="box x"></div>
<div class="box y"></div>

  • But you also never make it easy, right?! I’m just waiting for the question to be edited by adding the phrase "No SVG please"

  • @fernandosavio wants to go soft? Sit in the pudding! D

1 answer

9


With ::before and ::after only in the first div can you:

.container{
  position: relative;
}

.box, .box.x::before, .box.x::after {
  width: 200px;
  height: 200px;
  box-sizing: border-box;
  position: absolute;
  border-radius: 50%;
  border: 20px solid tomato;
}

.box.x::before, .box.x::after{
   content: '';
   top: -20px;
}

.box.x::before{
   left: -20px;
   border-bottom-color: transparent;
   z-index: inherit;
}

.box.x, .box.x::after{
   box-shadow: 0 0 15px 0 rgba(0, 0, 0, .75);
}

.box.x::after{
   left: 80px;
   border-top-color: transparent;
}

.box.x {
   z-index: 20;
} 

.box.y {
   left: 100px;
}
<div class="container">
   <div class="box x"></div>
   <div class="box y"></div>
</div>

The idea is that the div.x has a z-index higher than the div.y and the ::before be on top with the transparent bottom edge so that the edge of the ::after over. The same thing with the ::after, only with the transparent top edge.

The shadow (box-shadow) applied only to div.x and in your ::after, because, like the ::after is over the div.y, this div doesn’t need the shadow.

Shadow issue

I had to create a pseudo ::before in div.y and change the shadow to inset in the pseudo ::before of div.x and use two shadows, one inset and another outset (standard) in the pseudo ::after of div.x:

.container{
  position: relative;
}

.box, .box.x::before, .box.x::after, .box.y::before{
  width: 200px;
  height: 200px;
  box-sizing: border-box;
  position: absolute;
  border-radius: 50%;
  border: 20px solid tomato;
  background-color: transparent;
}

.box.x::before, .box.x::after, .box.y::before{
   content: '';
   top: -20px;
}

.box.x::before{
   left: -20px;
   border-bottom-color: transparent;
   z-index: inherit;
   box-shadow: inset 0 0 15px 0 rgba(0, 0, 0, .75);
}

.box.x, .box.x::after{
   box-shadow: 0 0 15px 0 rgba(0, 0, 0, .75);
}

.box.x::after{
   left: 80px;
   border-top-color: transparent;
   box-shadow: inset 0 0 15px 0 rgba(0, 0, 0, .75), 0 0 15px 0 rgba(0, 0, 0, .75);
}

.box.y::before{
   left: -20px;
   z-index: 20;
   border-top-color: transparent;
}

.box.x {
   z-index: 20;
} 

.box.y {
   left: 100px;
}
<div class="container">
   <div class="box x"></div>
   <div class="box y"></div>
</div>

  • Very good Sam has reached 90%, only that the element has a total shadow, like everywhere, notices there in the intercession of images and notices how is the shadow between the elements

  • In the shadow of your example the code only has shadow out.

  • 1

    +1. I think you just change the shadows to give the impression that you are on top: .box.x { box-shadow: 0 2px 10px 0 rgba(0, 0, 0, .75) inset } .box.x::after { box-shadow: 0 0 15px 0 rgba(0, 0, 0, .75) }: https://i.imgur.com/Aoui9jc.png

  • Yes Sam, there’s no reason why I couldn’t do it. But the intention is to make it equal to the reference image as I commented on the question. It is a detail that in my view makes a difference, because of the more depth in the "interlaced" of the elements. The intention as I said was to arrive in the form of the image, as I could not get there I left the question here.... although it was very good, as I had already said.

  • @hugocsl I added in the reply. Abs!

  • See, it wasn’t so hard ;) vlw

  • @Renan Valeu! Got it with a shadow inset :D

  • 1

    I’m impressed with your Skills, it looks great.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.