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:

https://i.sstatic.net/n7blo.png https://i.sstatic.net/8EIdQ.png

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

https://i.sstatic.net/y1vs1.png https://i.sstatic.net/xNfE9.png

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

What steps do I need to take in order to transform this code into a MUI component complete with

Having some trouble converting my hero banner code to MUI in a React project. The styling is not coming out correctly. Here is the HTML code: <svg data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 120 ...

What is the proper way to address the issue of nesting ternary expressions when it comes to conditionally rendering components?

When using the code below, eslint detects errors: {authModal.mode === 'login' ? <Login /> : authModal.mode === 'register' ? <SignUp /> : <ForgotPassword />} Error: Avoid nesting ternary expressions. eslint(no-nested-t ...

Arranging inline-flex elements within a div container

I have been struggling to position two elements side by side within a single div, where the second element should be on the right side. <div className={classes.container}> <div className={classes.first}> First </div> <d ...

Building custom MDX components with attribute-based data manipulation techniques

Can custom MDX components be defined using a data-attribute of the HTML element? Currently, I am developing a Next.js blog utilizing contentlayer for MDX and Rehype Pretty Code for syntax highlighting code blocks. The HTML output structure from Rehype Pre ...

Background elements in React Bootstrap Modal are not fully shaded

While utilizing the React Bootstrap modal, I noticed that when it is open, the background is usually shaded and overlayed with the modal. However, I encountered an issue where certain elements, specifically the Material UI Drawer, do not get shaded and ins ...

What is the best practice for creating helper functions in React components?

I have noticed a recurring issue of code duplication in my projects, particularly with basic helper functions like the one shown below: function percentageWithCommas(x?) { try { return (x * 100).toLocaleString("en-UK", { maximumFractionDigits: ...

Display overlay objects specifically focused around the mouse cursor, regardless of its position on the screen

I am currently working on a project using SVG files and processing.js to develop a unique homepage that incorporates both animation and static elements. The concept is to maintain the overall structure of the original homepage but with varying colors, esse ...

Adjust the translateZ value according to the dynamic height of the element

A unique rotating cube effect has been developed using 3D css transformations. To achieve this, the following transform is applied to a child element: transform: translateY(-50%) translateZ(-75px) rotateX(90deg) ; In addition, the parent element contain ...

Typescript Routing Issue - This call does not match any overloads

Need assistance with redirecting to a sign-up page upon button click. Currently encountering a 'no overload matches this call' error in TypeScript. Have tried researching the issue online, but it's quite broad, and being new to Typescript ma ...

Pagination with React Material UI is a user-friendly and visually

Requirement Within the Material UI framework, I need to implement pagination functionality by clicking on the page numbers (e.g., 1, 2) to make an API call with a limit of 10 and an offset incrementing from 10 after the initial call. https://i.stack.imgur. ...

Having trouble implementing letter-by-letter animation in ReactJS (NextJS)?

My issue lies in my attempt to display a text word by word on a website, iterating through each word. I am utilizing state variables to append the words, which are set within a useEffect. The approach I took involved calling useEffect(), writing the first ...

Vuetify's Handy Helper Classes

Hey everyone, I'm working on a vuetify project and I need to convert inline styles to utility classes (if possible) font-size: 24px; font-weight :600 I checked the documentation and noticed that it only provides options for setting size and weight wi ...

Transforming a horizontal list into a vertical one

What might be causing the message list to display horizontally in the admin dashboard, but vertically on other pages? .user-list{ display:inline; } .users header, .users-list a{ display: flex; align-items: center; padding-bottom: 20px; border-bottom: 1px s ...

Font animation experiencing limited functionality

As a beginner in the world of programming, I am facing some challenges with my animation. The struggle lies in the fact that only my "Treats" are moving and not the "Tricks". Any guidance or suggestions would be greatly welcomed as I might have jumped into ...

Is there a way to ensure that the navigation tabs in Tailwind always display a scroll bar?

My navigation bar contains multiple tabs that require scrolling to be fully visible. On the initial load, users may not realize they can scroll to see additional tabs. To address this issue, I want to always display a scrollbar on the navigation bar. ...

Erase a set of characters with the press of the backspace key (JavaScript)

Within my textarea, I have lines that start with a number and a period: <textarea autoFocus id="text-area"wrap="hard" defaultValue ={this.state.textAreaVal} onKeyUp={this._editTextArea}/> For example: Line 1 Line 2 Line 3 I've created a ...

The environmental factors in Turbo are crucial for optimizing performance

I'm having trouble accessing an environmental variable from my local .env file in one of my turbo packages. Every time I try to use it, it returns as undefined. My project is using Turbo to manage a monorepo and is built with Next.js/React/Typescript. ...

The CSS3 transition is not functioning correctly when transitioning element dimensions from a percentage or auto value to a specific pixel

As part of my project, I am developing a single-page website that features a vector graphic occupying 80% of the screen width on the initial 'start screen'. Once the user scrolls down, the graphic smoothly transitions into a navigation bar positi ...

Previewing the small version, loading the URL into a container

Currently, I am working with jQuery's .load(url, ...) function to bring in a url and display it within a div. However, I am facing an issue where the result needs to be resized in order to fit correctly within the layout. Can anyone provide guidance o ...

Troubleshooting the issue of CSS animations activating twice and causing a flickering effect specifically in the Firefox browser

I am facing an issue with CSS animations in Firefox. When I try to slide in some radio buttons upon clicking a button, the animation seems to be firing twice in Firefox while it works fine in Chrome. I have attempted several solutions but haven't been ...