Home  >  Article  >  Web Front-end  >  Why Doesn\'t Z-Index Work on Pseudo-Elements with Transform?

Why Doesn\'t Z-Index Work on Pseudo-Elements with Transform?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-31 09:43:30803browse

Why Doesn't Z-Index Work on Pseudo-Elements with Transform?

Z-Index Not Affecting Outer Ring

When attempting to move an outside ring behind a circle using CSS, you may encounter an issue where the z-index property seems ineffective. In this case, the problem lies with the transform property being applied to the pseudo-elements.

<code class="css">#background #mainplanet:before,#background #mainplanet:after {
  ...
  transform: rotateX(66deg) rotateY(170deg);
}</code>

To address this, you need to remove the transform property and replace it with alternative positioning methods, such as adjusting the top and left coordinates or using absolute positioning with calculated values.

<code class="css">#background #mainplanet:before,#background #mainplanet:after {
  ...
  top: calc(10px - var(--size) / 4);
  left: calc(-80px - var(--size) / 4);
}</code>

By making these changes, you should regain control over the z-index property and be able to effectively move the pseudo-element behind the circle as intended.

The above is the detailed content of Why Doesn\'t Z-Index Work on Pseudo-Elements with Transform?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn