Problem: Tailwind CSS styles are not being applied on responsive screens in Next.js.Issue: Despite

I'm attempting to apply a custom class to a div that should only be active on "md" screens. However, it doesn't seem to be working -

<div className="md:myclass"/>

tailwind-config.ts

theme: {
    screens:{
      'sm': {
        'min' : '320px',
        'max' : '767px'
      },
      'md': {
        'min': '768px',
        'max': '1023px'
      },
      'lg': '1024px',
      'xl': '1280px',
      '2xl': '1536px'
    },
}
}

globals.css // imported in my layout

.myClass{
 background: yellow;
}

Skeptical, I decided to test if ":md" was functional or not by adding "md:hidden" and confirmed that it does hide the element.

<div className="md:hidden"/>

I also double-checked if the class was imported correctly by trying to apply it directly without md: and observed that it worked properly.

<div className="myclass"/>

Is there another method to include my own custom class for responsive design, or am I overlooking something..

Answer №1

If you want to include your unique classes, you must insert them in one of the predefined Tailwind layers in the globals.css file. For more information on this topic, check out the Tailwind documentation

/* globals.css */

@layer components {
  .myclass {
    background: yellow;
  }
}

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

Troubles with proper functionality of antd's DatePicker.RangePicker within a React Function Component

I am currently utilizing React and the antd library, attempting to incorporate the DatePicker.RangePicker into my project. Initially, when I directly embed the RangePicker within the component, everything works smoothly. However, for better code organizat ...

How to design input elements for adding new rows in Material Table

Looking to expand the width of a drop-down list labeled "Birth Place" within the Materialtable component in ReactJS. https://i.sstatic.net/SM77u.png I am aiming for a design similar to the image attached, but I am unsure where to apply the CSS code &apos ...

Adjust the stroke and fill colors of an SVG element when hovering over it

I am facing a challenge with an SVG image that I have: https://i.stack.imgur.com/r4XaX.png When hovered over or clicked, it should change to https://i.stack.imgur.com/EHRG2.png Current Icon <svg width="24" height="24" viewBox="0 0 24 24" fill="non ...

Step by step guide to showcasing images dynamically in user interface

My current project involves displaying a screen with an HTML table and an image. The HTML table is fully dynamic. The Code Working Process When the user loads a page (with a URL), I render an HTML table in different parts as the page loads. I retrieve al ...

Is there a way to drop a pin on the Google Maps app?

Is there a way to pinpoint the specific location on Google Maps? <google-map id="map-container" width="100%" height="100%" class="maps"></google-map> ...

Positioning divs around a circle can be quite challenging

Among my collection of divs with various classes and multiple child divs representing guests at a table, each main div symbolizes a specific restaurant table type. I have created a jsfiddle for demonstration. http://jsfiddle.net/rkqBD/ In the provided ex ...

Highlighting table rows when hovering in IE with JQuery - compatibility across all versions

I have a table on my jsp page with multiple rows and columns. I want to ensure that visitors can easily follow along when they interact with the table - by highlighting the row or column they hover over with a different background color. Although the **hov ...

Tips for incorporating an entire JavaScript file into a React JS project

I'm facing an issue with a .js file (JavaScript file) that lacks exports code, containing only a constructor and some prototype methods. I am trying to incorporate this file into my ReactJS App. My approach involved adding a script tag in client/inde ...

Tips for modifiying date format in React app

I'm encountering an issue where I can't modify the date format, preventing me from displaying the date on the frontend. Currently, I'm utilizing the dateformat package. import dateFormat from "dateformat"; const EditFinancialInfo ...

Issue with calling hooks. Hooks can only be invoked within the body of a function component

Looking to develop a todo application using React, but encountering an issue with the useContext hook. The error message "Invalid hook call..." suggests a few possible reasons for this problem: Possible mismatched versions of React and the renderer (e.g ...

Problem with loading images on an HTML webpage

After refreshing the page, I'm encountering an issue where the image is not loading. However, if I switch tabs from MEN to WOMEN and back again, the image will display without any problem. Even making changes in the CSS doesn't seem to affect thi ...

Promise-based React Redux Login: An error occurred during login process

I'm currently working on my first React+Redux application and I'm still in the scaffolding phase. As a newcomer to React, I've encountered an issue with my simple login app. The AuthAction returns a Promise from the login(username, password) ...

Tips for improving my page's performance in React/Next.js without triggering excessive re-renders

Hey there! I recently worked on enhancing a user profile editing page in my react project. The page includes a dropdown selector from the react-select library and an input text box. To manage states, I utilized zustand. Everything was running smoothly unti ...

Is it possible to utilize both React-Redux and React Context API simultaneously within a single project?

After years of experience as an Angular developer, I decided to explore React & React Native for some new projects. However, I faced a challenge when it came to choosing the best state management solution for potential scalability. My question is, wo ...

Why is my React Native button's onPress event not functioning correctly?

I am encountering an issue with the onPress event handler. I have tried multiple solutions but none seem to work with the handleClick function. Here are the different approaches I attempted: onPress={this.handleClick} onPress={this.handleClick()} onPress= ...

React Query: No overload is a match for this specific call

I encountered an issue while attempting to create a custom hook called useProfile. The error message below has left me puzzled, and I am unsure of how to resolve it: [{ "resource": "/D:/AniMi/animi-next/hooks/useProfile.ts", &qu ...

How can you reset the inner navigation stack in React-Native?

As someone who is new to react-native, I am currently creating an app with a bottom tab navigation. To achieve this, I have utilized the react-navigation-material-bottom-tabs library, which has been working flawlessly so far. My bottom tab navigator includ ...

Obtaining the Hostname for server-side fetch in NextJS13 component on Vercel platform

When working with a server-side component in NextJS13 and using the fetch function, the code typically looks like this: fetch("http://localhost:3000/api/test") The endpoint URL ("/api/test") can vary depending on the environment in which it is d ...

I'm currently developing a Chrome application specifically designed for editing plain text. To achieve this, I am utilizing the <textarea> element. However, the app will not expand to full screen

Currently, I am in the process of developing a Chrome app and have implemented CSS from a previous post. The main issue I am facing is with the textarea element that I am using. I am open to exploring alternative solutions to achieve the desired outcome. S ...

Tips for successfully passing an empty value as a prop on a Material UI button

Currently, I am utilizing a ternary operator in a prop for a button. It is functioning as expected, but a warning regarding the empty string keeps appearing in the browser. I am looking for an alternative solution to avoid this error. <Button varia ...