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

Mary-Kate Olsen
Release: 2024-10-31 09:43:30
Original
818 people have browsed it

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>
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!