My custom class is being ignored by Tailwind CSS within breakpoints

I'm attempting to incorporate some animation on the height property within the md breakpoint, but for some reason Tailwind CSS isn't applying my class.

 <div className={`h-12 bg-blue flex w-full text-white fixed mt-1 md:bg-white ${scrolling ? 'md:animationNav md:h-16' : 'md:animationBasisNav md:h-20'} lg:bg-gray-500 `}>
<p>test</p>
</div>

Here's my SASS:

.animationNav{
    -webkit-transition: height 1s ease-in-out;
    transition: height 1s ease-in-out;

    img{
        -webkit-transition: padding 1s ease-in-out;
        transition: padding 1s ease-in-out;
        padding: 0;
    }
}
.animationBasisNav{
    -webkit-transition: height 1s ease-in-out;
    transition: height 1s ease-in-out;
    img{
        -webkit-transition: padding 1s ease-in-out;
        transition: padding 1s ease-in-out;
        padding: 0.25rem
    }
}

I've tried adding it to the TailwindCSS utilities like this, but it still doesn't work:

@layer utilities {
    .animationNav{
        -webkit-transition: height 1s ease-in-out;
        transition: height 1s ease-in-out;
    
        img{
            -webkit-transition: padding 1s ease-in-out;
            transition: padding 1s ease-in-out;
            padding: 0;
        }
    }
    .animationBasisNav{
        -webkit-transition: height 1s ease-in-out;
        transition: height 1s ease-in-out;
        img{
            -webkit-transition: padding 1s ease-in-out;
            transition: padding 1s ease-in-out;
            padding: 0.25rem
        }
    }

}

Upon loading the page:

Although scrolling triggers the height adjustment inside md, my class names do not get applied:

Any thoughts on why Tailwind CSS is ignoring my class? Do I need to configure something in the tailwind.config.js file?

Answer №1

To incorporate responsive variations into your custom classes, the recommended method is to utilize @responsive:

@responsive {
  .animationNav { ... }
}

/* Output */

.animationNav { ... }

@media (min-width: 640px) {
  .sm\:animationNav { ... }
}

@media (min-width: 768px) {
  .md\:animationNav { ... }
}

/* etc. */

Key points from the documentation:

This offers a shortcut for using @variants responsive { ... }, which achieves the same result.

The responsive variants will be integrated into Tailwind's current media queries at the conclusion of your stylesheet. This ensures that classes with a responsive prefix take precedence over non-responsive classes targeting the same CSS property.

Answer №2

Are you looking to incorporate a fresh utility into your project? One method is to create the new utilities directly in your CSS using the @layer notation.

@layer 
 helpers {
  .customUtility {
   // Your custom styles here
  }

//continue adding new utilities as needed

For more detailed information, check out this documentation: https://tailwindcss.com/docs/adding-new-utilities

Answer №3

simple as ABC

@screen md {
  // do something
}

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

Navigating to an external website in NextJs using Strapi

I am facing an issue where I need to redirect the user to a specific link stored as a data value in my Strapi CMS. When using <a href> tag, it redirects me to http://localhost:3000/www.google.com. How can I remove the localhost part from the URL? I h ...

Is there a way to position the drop-down menu in front of the slider?

Hey there, I'm currently experiencing some issues with the drop-down menu on my index page. The drop-down items are hidden below my image slider, which is directly underneath my navigation bar. I would really appreciate any help in fixing this so that ...

Jest tests failing due to broken linked library

We developed a React library for use in another application. However, when attempting to link the library using npm link ../myLibrary, Jest tests fail with an error message: TypeError: Cannot read property 'webpackChunk_my_library' of undefined ...

Include a tooltip on every image by utilizing the title attribute

<br><img title="Cool as ninja!" src="/images/profile2.png" width="300"></br> <br> <strong>Who's this pretty girl ninja!?</strong> <br><img title="Cool dude bro!" src="/images/profile5.png"></br> & ...

What is the best way to align a div with a fixed width in the center, when it is positioned between two other divs within a parent

I have this HTML (technically JSX) code snippet here: The center div with the class domain-input-parent is supposed to have a fixed width of 400px and stay centered horizontally on the screen. This arrangement ensures that both the domain-label and icon- ...

What is the process for transferring image attributes to the server via a URL?

My data transmission process only involves sending data. Below is the data I send: export const cabin = { name: '001', maxCapacity: 2, regularPrice: 250, discount: 0, image: './cabins/cabin-001.jpg', description: ...

A unique technique for creating a stunning visual effect with images using

Can anyone help me with this issue: Check out this animated GIF The images in my project are overlapping when scrolling! How can I achieve a similar effect for my images? Is there a tutorial or plugin available for this? Here is the current code sn ...

When render returns another component, React does not invoke componentWillMount

Here is my code setup: const Dashboard = React.createClass({ getInitialState(){ return { user: JSON.parse(localStorage.getItem('user')) }; }, componentWillMount(){ var self = this; $.get({ url: 'http://127 ...

"Implementing CSS inline styles for improved appearance on a Safari browser when visiting

Having some trouble using CSS to create rounded corners on my Facebook fan page. Everything works fine except for Safari browser. I've tried inline styles and a separate stylesheet, but no luck. Any help would be appreciated. My CSS for rounded corne ...

Animated CSS sidemenu (utilized as a filtering panel for a table)

Hi there, I'm having some trouble with CSS Animation. I recently started developing websites and am using Bootstrap 4 along with Animate.css for animations. My goal is to have an icon button expand sideways to reveal a div containing select elements f ...

Only one multi-dependency useEffect call is triggered when new values are sequentially set

Monitoring for changes in 2 key variables, step and reviewElementId, my useEffect is designed to trigger when either of them are updated. useEffect(() => { //... }, [step, reviewElementId]); When a function called update is executed, it sequentiall ...

Is it possible for me to overlap a text over hidden text, and if the hidden text becomes visible through JavaScript, my text will shift to the right of the now visible hidden text?

I'm currently working on a website for a company that requires users to complete all the information before proceeding. To achieve this, I created a form with the following code: <form action="Owners Infoback.php" onsubmit="return validateFo ...

The filter search feature fails to return any results when data is inputted into the tables

I have implemented a filter search feature within two tables on my website. My goal is to retrieve the search results for a specific drink while keeping the table headings fixed in their positions. For instance, if I type "Corona" into the search box, I ...

"Encountering an error with AWS Amplify, Next.JS, and GraphQL Server: Unable to retrieve current user in

I'm encountering an issue with accessing data from Amplify's API Graphql, as it consistently returns Server Error Error: No current user I've been referring to this tutorial: https://youtu.be/13nYLmjZ0Ys?t=2292 Even though I have successfu ...

Discover the secrets of extracting the ID from a MenuItem within a Menu

Table Ui with menu Struggling with fetching the correct user ID in the edit button The edit button for all users is only displaying the last user's ID If the edit button is not nested inside the Menu, it works fine. However, within the Menu, it onl ...

Display the title of an image beneath the image using CSS

Since upgrading my CMS, I've encountered an issue where the captions of images are not showing below the image for thousands of articles. For example: <img src="123.jpg" alt="Texttext" class="caption" style="disp ...

Decorative initials have a tendency to create spaces within the text

I have incorporated Google Fonts into my website, along with Bootstrap. Here is the code I am using: .initial { font-size: 1.5em; font-family: 'Euphoria Script', cursive; } p { font-family: 'Open Sans', sans-serif; } <html> ...

What are the specifications for the opacity, width, and height of the background image in Bootstrap's

My current project has specific requirements that I need assistance with: I need the background image of the jumbotron to fit the width of the page and have its height scaled proportionally. The opacity of the jumbotron's background image should be ...

Converting line breaks into a visible string format within Angular

After thorough research, all I've come across are solutions that demonstrate how to display the newline character as a new line. I specifically aim to exhibit the "\n" as a string within an Angular view. It appears that Angular disrega ...

What could be the reason for the malfunctioning of my express delete request?

When I send a delete request using Postman on my localhost, everything functions correctly. However, when trying to make the same request from my React.js client-side, it doesn't go through. Below is the API request: router.delete("/deletetransaction ...