Some of the Tailwind CSS colors may not be fully supported by Next.js for rendering

Don't forget to showcase all the amazing Tailwind CSS Colors,

Sometimes they go missing unexpectedly,

and only a few decide to make an appearance.

I try to add them manually one by one, but sometimes they just don't show up on the map.

Edit: I've added the key for each color, set them individually, and refreshing doesn't give the expected result.

export function Twcolors(props: TwcolorsProps) {
  const colors = ['', 'slate', 'gray', 'zinc', 'neutral', 'stone', 'red', 'orange', 'amber', 'yellow', 'lime', 'green', 'emerald', 'teal', 'cyan', 'sky', 'blue', 'indigo', 'violet', 'purple', 'fuchsia', 'pink', 'rose']
  return (
    <>
      <main className="flex w-screen flex flex-col items-center justify-center">
        <h1 className="text-4xl mt-3 font-extrabold text-gray-900 tracking-tight text-indigo-500">
          Check Out Tailwind CSS Colors</h1>
        <p className="my-4 text-center leading-loose">
          <code className="bg-gray-200 px-3 py-1 rounded-lg">-inherit</code>
          <code className="bg-gray-200 px-3 py-1 rounded-lg">-current</code>
          <code className="bg-gray-200 px-3 py-1 rounded-lg">-transparent</code>
          <code
            className="bg-gray-200 px-3 py-1 rounded-lg">-black</code>
          <code
            className="bg-gray-200 px-3 py-1 rounded-lg">-white</code>
          <br/>And many more:</p>


        <div className="bg-neutral-300"> Some</div>
        {
          colors.map(
            (color) => (
             
              <div key={color.toString()} className="grid grid-rows-10 grid-flow-col items-left">
                <h2 key={color.toString()}>{color} {`bg-${color}-50`}</h2>
                <div key={color.toString()}
                     className={`h-12 w-24 m-1 flex items-center justify-center rounded-xl bg-${color}-50`}>50
                </div>
                <div key={color.toString()}
                     className={`h-12 w-24 m-1 flex items-center justify-center rounded-xl bg-${color}-100`}>100
                </div>
                <div key={color.toString()}
                     className={`h-12 w-24 m-1 flex items-center justify-center rounded-xl bg-${color}-200`}>200
                </div>
                <div key={color.toString()}
                     className={`h-12 w-24 m-1 flex items-center justify-center rounded-xl bg-${color}-300`}>300
                </div>
                
              </div>


            )
          )
        }

      </main>

    </>

  )
    ;
}

export default Twcolors;

https://i.sstatic.net/Fmh3a.jpg

Answer №1

The reason for this issue is due to the usage of dynamic class names, which Tailwind cannot detect because they are not predefined in its configuration. You can find more information on this topic here: https://tailwindcss.com/docs/content-configuration#dynamic-class-names

If you notice any "random" classes appearing, it is likely because they are being utilized elsewhere in your code.

To resolve the problem, manually include each color class instead of relying on dynamic naming.

By observing the Tailwind Colors page, you will observe that all colors are rendered using inline styles rather than Tailwind classes. Check it out here: https://tailwindcss.com/docs/customizing-colors

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

How come I am unable to connect my CSS to my EJS files?

Having difficulty linking my css files to my ejs files. Using a standard node.js/express setup, I'm attempting to connect my main.css file from the public/css directory to my index.ejs file in views. The html and routing are functioning correctly. Ple ...

Is barrel(index) file usage supported by Next.js 11.0.0?

When using barrel/index files with next.js, it appears to cause issues. It is unclear whether this is solely a webpack problem or if both webpack and next.js are affected. As stated in this report, tree shaking stops functioning properly when barrel files ...

Change the background color of cells according to the value they contain

I have a scenario where I am populating a table with random numbers, and I want the background color of each cell to change based on the value of the number in that cell. Since these numbers refresh periodically, I need the colors to update accordingly as ...

Ways to center a div with position:relative vertically on the page

What is the best way to center a position relative div vertically within its parent element? For example: <div class="parent"> <div style="position:relative;" class="child"> </div> </div> Any suggestions on how to vertic ...

What is the best way to automatically close a modal window after pressing the submit button

Having some trouble with my modal window using pure CSS. Can't seem to get it to disappear after clicking the submit button. Any suggestions on how to hide it properly? Here is the code snippet of both the HTML and CSS for reference. Open to all ideas ...

Combining the jquery-UI slider functionality with the canvas rotate() method

Is there a way to rotate an image using html2canvas plugin and jQuery UI slider? I am new to programming and need some guidance on how to achieve this feature. Here is my current progress: http://jsfiddle.net/davadi/3d3wbpt7/3/ ` $("#slider").slider({ ...

Using a color as a substitute for a background image on mobile devices

Is there a way to create a fallback in my CSS for changing the background image to a color when viewed on a mobile browser once the pixels reach the max-width? In the snippet below, the media query "only screen and (max-width: 600px)" works if the top bod ...

The Next JS build process is failing to generate certain paths

Issue with Anime Database App Deployment A problem arose when I developed an anime database app using Nextjs and deployed it on Vercel. Although the build was successful and the initial page rendered properly, only a few dynamic routes displayed correctly ...

specific css styles only for Safari and Internet Explorer

Imagine a scenario where I have a div with the class 'x': <div class = 'x' /> This div has some CSS properties and what's interesting is that it appears differently in Safari and the latest version of IE compared to other ...

Trouble toggling Reactstrap navbar in my TypeScript project using NextJS

I recently integrated Reactstrap into my NextJS TypeScript project and encountered an issue with the Navbar component. Despite following the example from the Reactstrap documentation, the mobile toggle menu does not open when clicked. Additionally, none of ...

Arrange elements side by side within siblings, while keeping the HTML structure intact

As evident from the code snippet, there are 2 dynamically generated flex divs (although there could be more). Is there a method to horizontally align items on larger screens without altering the HTML structure? I am seeking something similar to: .de ...

Tips for creating a background image that seamlessly adjusts to various computer screen sizes

I am trying to make sure that an image fills the entire browser window, but unfortunately it has fixed width and height dimensions. Is there a way to adjust this so it displays correctly on screens of different sizes? Can CSS be used to stretch the backg ...

Responsive Text and Alignment in the Latest Bootstrap 5

My goal is to center my div element while keeping the text aligned to the left. Here's the code I have: <div class="container"> <div class="row"> <div class="col"> <h1>< ...

Design the appearance of page buttons distinct from select buttons

I am currently working on styling my paging buttons differently from the select buttons. However, the selector I am using for the select buttons is also being applied to the paging buttons: .gridView tr td a{} /* The gridView class has been assigned to th ...

Is there a way to efficiently create an ng-repeat for multiple divs?

I am looking to iterate through a collection of divs, as mentioned below. Each object in the list will have content-data and a link to an image. The code provided shows individual entries for each list item, but I would like to retrieve it from the angular ...

Filtering a collection in Firestore using the `where()` method for a context provider in Next.js

i encountered an issue: when using the useEffect function to retrieve my firestore documents, it works well. Currently, I am fetching all "profiles" documents (3 in total). However, I now want to only retrieve the documents where the field "workerProfile" ...

Utilize Flexbox to arrange elements in a column direction without relying on the position property in CSS

Flexbox - align element to the right using flex-direction: column; without relying on position in CSS Hello everyone, I am looking to move my row element to the right without using positioning. This code includes flex-direction: column; and I do not have ...

The main menu items in jQuery do not display the child sub menu upon clicking

I'm currently in the process of creating a unique mobile menu for my Wordpress website, but I'm facing some challenges when it comes to displaying and hiding the sub-menu items. I've assigned the class name .menu-item-has-children as my sele ...

CSS Problem: Background Color Not Showing Up in Table Rows

Check out my fiddle below: https://jsfiddle.net/teo7auv3/ I'm facing a challenge where I want to change the background color of the entire table row (TR) to red when there are validation errors. The problem seems to be related to this code snippet: ...

Choosing the initial offspring of an element that do not share a common parent

My question might not be perfectly phrased, for which I apologize. Is there a CSS method to select only the first child of an element without affecting others that are not grouped under the same parent? For instance: <div class="parent"> <div ...