Home > Enterprise >  Tailwindcss box shadow not showing
Tailwindcss box shadow not showing

Time:01-01

I'm trying to use Tailwindcss in a React project where I am replicating the Star Wars website mobile menu. However, the box shadow that I am adding to the hamburger icon segments is not showing up when the nav drawer is opened.

index.js:

const toggleDrawer = (event) => {
  document.querySelector("#drawer").classList.toggle("left-[-100%]");
  document.querySelector("#drawer").classList.toggle("left-0");
  document.querySelector("#bar-1").classList.toggle("hidden");
  document.querySelector("#bar-2").classList.toggle("active-2");
  document.querySelector("#bar-3").classList.toggle("active-3");
};

<div
  onClick={toggleDrawer}
  className="h-full flex flex-col justify-center items-center space-y-[8px]"
>
  <span
    id="bar-1"
    className="block h-[2px] w-[30px] border-zinc-500 border-l-[4px] border-r-[20px] rounded-full transition-all duration-300"
  ></span>
  <span
    id="bar-2"
    className="block h-[2px] w-[30px] border-zinc-500 shadow-md border-l-[20px] border-r-[4px] rounded-full origin-bottom-right transition-all duration-300"
  ></span>
  <span
    id="bar-3"
    className="block h-[2px] w-[30px] border-zinc-500 shadow-md border-l-[4px] border-r-[20px] rounded-full origin-bottom-left transition-all duration-300"
  ></span>
</div>;

global.css:

@layer components {
  .active-2 {
    @apply
      rotate-45
      -translate-x-2
      translate-y-[530%]
      w-[34px]
      border-l-[25px]
      border-r-[5px]
      border-white
      shadow-[#d50032] !important;
  }
  .active-3 {
    @apply
      -rotate-45
      translate-x-1
      w-[34px]
      border-l-[5px]
      border-r-[25px]
      border-white
      shadow-[#106ae0] !important;
  }
}

CodePudding user response:

You are applying !important the wrong way. To add !important to a tailwind class just add ! add the start like this:

@layer components {
  .active-2 {
    @apply
      rotate-45
      -translate-x-2
      translate-y-[530%]
      w-[34px]
      border-l-[25px]
      border-r-[5px]
      border-white
      !shadow-[#d50032];
  }
  .active-3 {
    @apply
      -rotate-45
      translate-x-1
      w-[34px]
      border-l-[5px]
      border-r-[25px]
      border-white
      !shadow-[#106ae0];
  }
}

CodePudding user response:

You only have a shadow color declared. You also need a shadow size like shadow-md.

Here's an example on Tailwind Play showing the difference https://play.tailwindcss.com/gxG7cir5EQ

  • Related