"Troubleshooting: Why isn't my Tailwindcss box shadow

I'm currently incorporating Tailwindcss into a React project to recreate the Star Wars website mobile menu. However, I am facing an issue where the box shadow added to the hamburger icon segments is not visible when the navigation drawer is opened.

Access the sandbox here: https://play.tailwindcss.com/upmiAWTcso

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];
  }
  .active-3 {
    @apply
      -rotate-45
      translate-x-1
      !w-[34px]
      !border-l-[5px]
      !border-r-[25px]
      !border-white
      shadow-[#106ae0] !important;
  }
}

Answer №1

It seems you have only specified a shadow color, but you also need to include a shadow size such as shadow-md.

You can see the difference in this example on Tailwind Play: https://play.tailwindcss.com/gxG7cir5EQ

Answer №2

Incorrect usage of !important. The correct way to apply !important to a Tailwind class is by adding ! at the beginning 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];
  }
}

Answer №3

This issue appears to be related to browser compatibility.

It seems that the problem arises from a combination of border-radius and box-shadow properties. For example, when viewing this link in Opera, the desired effect is not achieved, whereas in Chrome it works fine. Removing the rounded corners reveals the shadow properly.

Answer №4

To successfully implement the shadow effect, it is essential to define the color of the shadow.

<div className="shadow-[#b6b6b6] shadow-lg"></div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adaptive Website displayed within an iframe

Currently, I have a responsive website that can be viewed here. The main objective is to embed this site into an iframe while maintaining its responsiveness. I attempted embedding my site in JSFiddle for testing purposes, which you can see here. However ...

Retrieve data from a MySQL table based on a specific condition in PHP

Can someone assist me with fetching data from a table where the valid_from date is less than a specified date (excluding the current date)? I have a table that looks like this: view my table here For instance, if my date is 02-04-2015, I would want to re ...

Refreshing a specific div within an HTML page

I am facing an issue with the navigation on my website. Currently, I have a div on the left side of the page containing a nav bar. However, when a user clicks a link in the nav bar, only the content on the right side of the page changes. Is there a way t ...

refresh the React component without having to refresh the entire webpage

Hey there, I have a component with a function called "handleAvatarUpload". Currently, when there is a change, the entire page reloads instead of just the component. Is there a way to reload only the component without refreshing the whole page? import { us ...

Creating SEO-friendly slug images in Next.js using the next/image component

Is it possible to change the image URL to a slug URL in Next.js using next/image? Currently, my image URL looks like: http://localhost:3000/_next/image?url=http%3A%2F%2F127.0.0.1%3A8000%2Fmedia%2Fuimages%2F0481%2F2408696.s.jpg&w=1920&q=75 Can I c ...

Unpacking objects within an array in the backend of a Next.js application

How can I resolve this issue? I am passing the req.query parameter with an array but I am unable to destructure or use items from the array. In my Next.js API backend, I only get [object Object] or undefined. How can I access and select specific values fro ...

Trigger a series of child functions upon clicking the parent button

I am facing an issue where I am attempting to trigger the functions of each child component from a button click event on the parent component. I have tried using props and setting up a new function in the componentDidMount lifecycle method, but only the la ...

Encountering error while using node-fetch in React application - "Module 'node:http' not found"

In my setup, I am using Strapi as a backend and React as a frontend. My main objective is to retrieve data from the API in the backend using any available tool. Initially, I attempted to use Axios for this task but encountered an issue when making a GET ca ...

Why does Visual Studio Code auto-complete "ImagePropTypes" when typing a dot after "props"?

Currently following a React Native tutorial with Visual Studio Code. Using Babel Javascript as my selected language mode. Encountering an issue when typing Line 7: https://i.stack.imgur.com/WcV7B.png After adding a period (.) to props, it changes to Ima ...

Having difficulty running a basic React program

I have been encountering issues while trying to run a basic React program as my localhost is not opening. Despite creating a workspace and successfully setting up the react hello world folder using 'npx create-react-app helloworld', I am unable t ...

What are the steps to designing an overlay using CSS?

Looking to generate a div with a custom size and then place something on top of it. How can I accurately position and resize the overlay to match the underlying div using CSS? ...

Guide to making a vertical clickable separator/line using bootstrap

Seeking advice on creating a layout where the left side consists of a sidebar menu occupying 24% and the right side contains main content taking up 75%, with a clickable vertical divider at 1% between them. When this line is clicked, the left part will hid ...

Updating the quantity of a product within a state in React allows for easy manipulation of that

My scenario involved attempting to reduce the quantity of a product object in the UI by clicking a button, but the quantity did not update as expected. What is the recommended course of action in situations like this? let product={ a:1,b:2,c:3}; For examp ...

Align the asp.net content generated towards the left side

I am looking to optimize the layout of my asp.net code by shifting the content on all pages to the left side of the screen for better efficiency. Despite my efforts, I have been unable to find a suitable CSS solution that works universally across all view ...

Children divs unexpectedly showing up outside of their parent divs

I have reviewed similar questions on this matter, but none of them seem to provide a solution for the issue I am facing. Currently, my goal is to display a stylized list, but I am encountering more difficulties than expected. You can find a fiddle linked ...

What is the reason behind React's decision not to use clusters in the `renderToString` method

Exploring Node.js Performance and Web Rendering Recently, I delved into the world of JavaScript performances and web rendering. I stumbled upon this insightful post which provided valuable information. While navigating through some links, I came across a ...

Can floated divs be prevented from collapsing without taking up any width?

Let's discuss an issue that is not related to block elements collapsing when their children are floated, and has nothing to do with clearing at all. Imagine having a set of floated divs like: <div class="column">Column 1</div> <div cl ...

Is there a way to align the image next to the form and ensure they are both the same size?

I've been struggling to resize the image to match the form size, but I can't seem to get it right. Can anyone provide me with some guidance on this issue? I have obtained this contact form from a website that I plan to modify slightly, but I need ...

Tips for solving the problem of TSX error where 'ReactNode' cannot be assigned with 'void' type

I've been attempting to loop through the Mui component MenuItem using a forEach loop, but I'm encountering an error stating 'Type 'void' is not assignable to type 'ReactNode''. Here's the section of my code caus ...

Compare several objects or arrays based on a selected array and combine them into a single object containing all matching elements from the selected array

selection = ["A", "lv3", "large"] Data = [{ id:1, title:"this is test 1", category:"A, D", level:"lv5", size: " medium", }, id:2, title:"this is test 1", category:"C ...