简体   繁体   English

如何在tailwindcss中使用z-index将元素隐藏在父元素后面?

[英]How to use z-index in tailwindcss for hiding an element behind the parent element?

The goal is to hide an element behind a parent.目标是将元素隐藏在父元素后面。 There is a relative parent position, and a fixed child position, so when you scroll down, the fixed child will become visible and the parent will go up.有一个相对父级 position 和一个固定子级 position,所以当您向下滚动时,固定子级将变为可见,父级将 go 向上。

The image with yellow border shall go behind黄色边框的图像应为 go 后面

在此处输入图像描述

Here's what I've tried:这是我尝试过的:

<!-- hamburger menu -->
<div class="relative bg-white z-50 border-2 border-purple-900 w-[34%] h-auto flex justify-end items-center">
    <div class="fixed top-6 right-1 z-20 border-2 border-yellow-500">
        <a class="lg:hidden inline-block float-right text-red-600 mr-[3px] mt-1 p-[6px] bg-white rounded-full border-2 border-yagya-red" href="#">
            <button id="mobile_menu1" class="relative outline-none w-7 h-7">
                <div role="hidden" id="line" class="inset-0 w-4 h-0.5 m-auto rounded-full bg-yagya-red transition duration-300"></div>
                <div role="hidden" id="line2" class="inset-0 w-4 h-0.5 mt-1 m-auto rounded-full bg-yagya-red transition duration-300"></div>
                <div role="hidden" id="line2" class="inset-0 w-4 h-0.5 mt-1 m-auto rounded-full bg-yagya-red transition duration-300"></div>
            </button>
        </a>
    </div>
</div>

thank you!谢谢你!

To add a z-index you have to use class:要添加 z-index,您必须使用 class:

  • z-10 : To bring that element forward z-10 : 把那个元素向前推进
  • -z-10 : To bring that element backward -z-10 :将该元素向后移动

You can take the below example你可以看下面的例子

 <script src="https://cdn.tailwindcss.com"></script> <!-- red with positive z-index --> <div class="p-10"> <div class="w-24 h-24 bg-red-600 rounded-full z-10 absolute"></div> <div class="w-24 h-24 bg-blue-600 rounded-full mt-10"></div> </div> <!-- red with negative z-index --> <div class="p-10"> <div class="w-24 h-24 bg-red-600 rounded-full -z-10 absolute"></div> <div class="w-24 h-24 bg-blue-600 rounded-full mt-10"></div> </div>

FInd more here在这里找到更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM