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

Utilizing an object map to pass objects as props without losing their keys

I have an array of objects named obj, structured as follows: { "root": [ { "key": "mihome", "label": "home", "action": "url", ...

Using Jest's moduleNameMapper with Next.js without TypeScript

I've been encountering some challenges trying to implement moduleNameMapper in NextJS using JavaScript. In this particular project, TypeScript is not being utilized. Next: 12.2.5 React: 18.2.0 Jest: 29.0.1 Jest environment jsdom: 29.0.1 Below is the ...

Struggling to center with margin 0 auto

I'm having trouble aligning the middle paragraph in an HTML footer. I attempted to use floats for layout: the first paragraph is floating to the left, the third paragraph is floating to the right, and the second (middle) paragraph has a margin of 0 au ...

The base64 encoded image is not appearing in the Material-UI CardMedia component

Hey there, I am currently working on integrating the material ui card component into my project. <CardMedia className={classes.media} title="Contemplative Reptile" src={'data:image/jpeg;base64,/9j/4AAQSkZJRgAtXpVp8YbaRdxnam/SvPJ/> ...

Tips on getting your card to stay at the top

Screenshot of webpage HTML (EJS): In the HTML file, look for the section after <%- include("navbar.ejs") -%> inside the body tag. The ".cardholder" contains "anime-card" templates (card.ejs). The first and last div within ".cardholder" are ...

Personalize the md-tab component in Angular 2

I'm encountering an issue with styling the md-tab component in Angular 2. While I understand that Angular 2 Materials is currently under development, I am wondering if there is a way to customize it, such as removing the bottom-radius. Below is an exa ...

Attempting to superimpose a CSS triangle arrow onto a Google Map

I'm currently working on incorporating a CSS arrow on top of a Google map as a design element. The concept involves a horizontal stripe with a downward arrow placed halfway through, and I aim to have this arrow overlay the Google map. Here is a snipp ...

Arrange the data in the table according to a predetermined default column

As a newcomer to ReactJS, I've implemented a table where you can sort the data by clicking on each column header. Here's a snippet of my code: import React, { useState, useEffect } from 'react' import { getUsers } from '../../servi ...

Discover how to utilize SX to access the theme colors in Material UI

What is the correct way to access the theme colors using the sx property? I attempted the following code but it was unsuccessful. <Card sx={{ border: "2px solid primary.main", }} > ...

Testing the axios mock with a 400 response does not result in the expected value being returned

Currently, I am utilizing nock to simulate my ajax call with axios. Below is the code snippet that I am working with: describe("unSuccessful rest call",()=>{ it('should dispatch types: SET_DROP_DOWN_CHECK_STATUS in order ', () => ...

Each time Firebase retrieves an object, it comes back with a unique name

One query has been bothering me: const questionsRef = firebase .database() .ref('Works') .orderByChild('firebaseKey') .equalTo(this.props.match.params.id); It's functional, but the issue lies in the output: "-LDvDwsIrf_SCwSinpMa ...

An always-visible navigation menu

After exploring various resources related to the same topic, such as sticky navigation bars and others, I noticed that all the solutions provided involved the use of this link http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js. However, inc ...

Expanding content to cover the entire width using CSS Bootstrap 5

As a newcomer to Bootstrap, I am working on customizing an existing Bootstrap example. My objective is to expand the width of the div tag (with id "inner") to fill the entire screen. I have experimented with various approaches, such as resetting the margi ...

A guide on embedding the flag status within the image tag

I would like to determine the status of the image within the img tag using a flag called "imagestatus" in the provided code: echo '<a href="#" class="swap-menu"><img id="menu_image" src="images/collapsed.gif" hspace = "2"/>'.$B-> ...

In-line Vertical Ticker Display

I attempted to use vTicker, but I found that it does not function properly when used as an inline element. <h1> <div id="vticker"><ul>...</ul></div> Some other headline text </h1> My goal is to have the vertica ...

Could I leverage a built-in function for comparisons when using React.memo?

I am utilizing a <Track/> component with an object as prop, similar to the following: const myData = { "location" : ["http://example.com/1.ogg", "http://example.com/2.mp3"], "identifier" : [" ...

Error: Unable to retrieve information from the /dashboard page

Building the frontend of my website with nextjs has been smooth until recently when I added some code that seems correct to my project. However, upon executing npm run build, an error was thrown indicating that nextjs failed to gather data for one of my p ...

Using XSLT to format HTML tables for printing

In my current project, I am developing an XSLT that retrieves a list of items from an XML file and generates an HTML table for each item. The issue I am facing is that when I attempt to print the document, the tables at the end of the page get cut off and ...

css problem with scaling in firefox

My goal is to create a website that adjusts its size based on the document size. When the document size is between 0px and 1024px, I want the design to be responsive. This can easily be achieved with CSS media queries. Similarly, when the document size is ...

Minimize the vertical gap between menu items when they wrap onto a new line

When examining the screenshot of the website, you'll notice a considerable space between the first and second rows of menu items. I'm aiming to minimize this spacing as much as possible. The following CSS pertains to this issue: .gva-navigatio ...