Home > Blockchain >  How to place line underneath the circle? without z-index
How to place line underneath the circle? without z-index

Time:11-17

I made an X with a circle using css.

There is a green line that is sticking out on top of the circle, how do I place it under the circle?

How would this be done?

code: enter image description here

.exitnew {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  box-sizing: border-box;
  margin: auto;
  padding: 0;
  width: 48px;
  height: 48px;
  cursor: pointer;
  background: blue;
  border: none;
  border-radius: 50%;
  clip-path: circle(50%);
  transition: all 1s ease;
  overflow: hidden;
}

.exitnew:before,
.exitnew:after {
  content: "";
  position: absolute;
  height: 5px;
  top: 22px;
  left: -1px;
  right: -1px;
  background: green;
  transform: rotate(45deg);
  transition: all 1s ease;
}

.exitnew:after {
  transform: rotate(-45deg);
}

.exitnew:hover {
  background: transparent;
}

.exitnew:hover:before,
.exitnew:hover:after {
  background: green;
}

.exitnew b {
  box-sizing: border-box;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border: 5px solid red;
  border-radius: 50%;
}
<button class="exitnew" type="button" aria-label="Close"><b></b></button>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

You just need to use z-index property on the :after CSS selector:

.exitnew {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  box-sizing: border-box;
  margin: auto;
  padding: 0;
  width: 48px;
  height: 48px;
  cursor: pointer;
  background: blue;
  border: none;
  border-radius: 50%;
  clip-path: circle(50%);
  transition: all 1s ease;
  overflow: hidden;
}

.exitnew:before,
.exitnew:after {
  content: "";
  position: absolute;
  height: 5px;
  top: 22px;
  left: -1px;
  right: -1px;
  background: green;
  transform: rotate(45deg);
  transition: all 1s ease;
  z-index: -1
}

.exitnew:after {
  transform: rotate(-45deg);
}

.exitnew:hover {
  background: transparent;
}

.exitnew:hover:before,
.exitnew:hover:after {
  background: green;
}

.exitnew b {
  box-sizing: border-box;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border: 5px solid red;
  border-radius: 50%;
}
<button class="exitnew" type="button" aria-label="Close"><b></b></button>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

You don't need all these code. Here is an easier idea:

.exitnew {
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  width: 48px;
  height: 48px;
  cursor: pointer;
  --b:7px;                /* the thickness*/
  --c:blue 90deg,green 0; /* the coloration */
  background:
    conic-gradient(from 90deg at var(--b) var(--b),var(--c)) 
    calc(100%   var(--b)/2) calc(100%   var(--b)/2)/
    calc(50%    var(--b))   calc(50%    var(--b));
  border: 5px solid red;;
  border-radius: 50%;
  transform:rotate(45deg);
}
<button class="exitnew" type="button" aria-label="Close"></button>
<iframe name="sif3" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

:before and :after are like html bread on you element sandwich. :before is the bottom slice, and :after is the top slice.

Add a negative z-index to the :before, :after styles and that will position your :after behind the button the same as the :before.

.exitnew:before,
.exitnew:after {
  content: "";
  position: absolute;
  height: 5px;
  top: 22px;
  left: -1px;
  right: -1px;
  background: green;
  transform: rotate(45deg);
  transition: all 1s ease;
  z-index: -1;
}

EDIT WITHOUT Z-INDEX

.exitnew {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  box-sizing: border-box;
  margin: auto;
  padding: 0;
  width: 48px;
  height: 48px;
  cursor: pointer;
  background: blue;
  border: none;
  border-radius: 50%;
  clip-path: circle(50%);
  transition: all 1s ease;
  overflow: hidden;
}

.exitnew:before,
.exitnew:after {
  content: "";
  position: absolute;
  height: 5px;
  width: 38px;
  top: 22px;
  left: 5px;
  right: 5px;
  background: green;
  transform: rotate(45deg);
  transition: all 1s ease;
}

.exitnew:after {
  transform: rotate(-45deg);
}

.exitnew:hover {
  background: transparent;
}

.exitnew:hover:before,
.exitnew:hover:after {
  background: green;
}

.exitnew b {
  box-sizing: border-box;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border: 5px solid red;
  border-radius: 50%;
}
<button class="exitnew" type="button" aria-label="Close"><b></b></button>
<iframe name="sif4" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

You can set the z-index property to send the green line(s) backward, "behind" the circle:

.exitnew:before,
.exitnew:after {
  content: "";
  position: absolute;
  height: 5px;
  top: 22px;
  left: -1px;
  right: -1px;
  background: green;
  transform: rotate(45deg);
  transition: all 1s ease;
  z-index: -1;
}

here's an example: https://jsfiddle.net/q7zprh4w/

CodePudding user response:

This is a solution without b and z-index:

.exitnew {
    position: relative;
    width: 48px;
    height: 48px;
    border: 5px solid red;
    border-radius: 50%;
    background-color: blue;
} 

.exitnew::before {
    content: "";
    display: block;
    position: absolute;
    width: 10.416%;
    height: 100%;
    top: 0;
    left: 44.792%;
    background-color: green;
    transform: rotate(45deg);
}

.exitnew::after {
    content: "";
    display: block;
    position: absolute;
    width: 10.416%;
    height: 100%;
    top: 0;
    left: 44.792%;
    background-color: green;
    transform: rotate(-45deg);
}

I put the red border to the button itself. So the two pseudo element ::before and ::after aren't overlapping the red border.

Note: I don't use box-sizing: border-box

  •  Tags:  
  • css
  • Related