Exploring the integration of pre-defined Tailwind classes within Next JS development

As I transition my project from Vite JS to Next JS, I am currently facing an issue with importing Tailwind styles from a file. Even though the file is being read by my project, the styles are not being applied as expected.

I'm wondering if there is a way to achieve similar functionality in Next JS or if there is another method I should consider.

// Example styles.js file located in the styles folder of a Next JS Project
export const styles = { padding: "sm:px-8 py-3" };

// Implementation in any component within the Next JS Project
import { styles } from "../styles/styles.js";

const About = () => (
 <div className={`${styles.padding} text-white`}>
  ...
 </div>
)

Answer №1

This is the content of the Tailwind file. I experimented with different methods using ChatGPT, but unfortunately, I did not achieve success.

// import { styles } from '@/styles/styles.js';

// const {styles} = require('./styles/styles');


/** @type {import('tailwindcss').Config} */
module.exports = {
  content: ["./components/**/*.{js,jsx}", "./pages/**/*.{js,jsx}"],
  mode: "jit",
  theme: {
    extend: {
      colors: {
        primary: "#050816",
        secondary: "#aaa6c3",
        tertiary: "#151030",
        "black-100": "#100d25",
        "black-200": "#090325",
        "white-100": "#f3f3f3",
      },
      boxShadow: {
        card: "0px 35px 120px -15px #211e35",
      },
      screens: {
        xs: "450px",
      },
      backgroundImage: {
        "hero-pattern": "url('/assets/herobg.png')",
      },
      // ...styles,
    },
  },
  plugins: [],
};

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

Sendgrid NodeJS has already received the previous email that was sent

My current tech stack includes NextJS, Firebase (Auth, DB, etc...), Vercel for hosting, OVH Domains, and using Node with NextJS for the backend. Recently, I have been experiencing strange behavior when sending emails using Sendgrid library or API v3 direc ...

Stylish dropdown menu design inspired by W3CSS website

I recently implemented a CSS dropdown menu example that I found on a website, but it's not working with my code. I double-checked for typos but couldn't find any. Even when I tried to directly copy the code and replace the content with my own, i ...

What causes the Material-UI Grid element to shift upon clicking it?

I have encountered an issue while developing a React app with Material UI. The problem arises on a specific page of the application. This particular page consists of text and a button aligned vertically, along with a second set of text and another button ...

What Triggers a 400 Bad Request In Django Graphene and NextJs When Using the useMutation Hook?

I have been working on developing a simple todo application using Django, Graphene, and NextJs. While I was successful in creating todos using graphiQL and Postman, I encountered a 400 Bad Request error when attempting to create a todo in NextJs. Even tryi ...

Looking for a prerequisite for running this script?

Seeking assistance from a skilled Javascript expert. I specialize in template development and utilize a specific script to display my footer link in all the free templates I create. If someone attempts to remove the footer link, their site will be redirec ...

Ways to improve the quality of a blurred photo

I've recently put together a test landing page using bootstrap: Upon visiting the site and viewing the iPhone screenshot, it's clear that the text on the screen is quite blurry. Interestingly, by simply resizing the browser window and then maxi ...

Can someone explain why the min-width property is not being respected by the <input> element?

Visit this link for the code The text field in the provided link should only be 10px wide but it is currently displaying a width of 152px. Here is the code snippet: .input { width: 100%; box-sizing: border-box; } .cont { padding: 2px; } .main ...

When HTML elements are dynamically inserted through JavaScript using quilljs, they may cause conflicts with the layout properties

I am currently working on creating a simple webpage layout similar to that of Stack Overflow, with a sidebar and a main content area that can scroll. In my case, the content area is intended to host a QuillJS text editor. To integrate the QuillJS editor i ...

Exploring the connection between a handful of documents using NextJs and Firebase

Wishing you a fantastic day! I'm a beginner with NextJs and I'm encountering an issue when trying to map my Firebase documents. I want to display 5 cards on my website, but I'm having trouble limiting the posts displayed. Here is my referen ...

Is there a way to insert images from a webpage in NextJs?

I am encountering issues while trying to incorporate the Coloplast logo into my project using this URL(https://www.coloplast.com/Global/1_Corporate_website/Press/Pics/CPlogo_Gray_RGB_300.png). **Unfortunately, I keep getting this error message ** Server ...

Next.js version 13 now gives an error stating that the "target" property is deprecated in next.config.js. In fact, the target property is no longer present in the next.config.js configuration file

After upgrading my next.js app to Next.js 13 and deploying the new version to AWS Amplify, I encountered a build failure with the following error message: The "target" property is no longer supported in next.config.js Error: The "target" propert ...

What is the optimal method to deploy a ReactJS web application on a production server?

Initially, my plan was to deploy a reactjs website on a production server using Apache. However, after doing some research on Google, I found multiple ways to serve a reactjs web app. For instance: Using Pm2 or simply starting it with 'next start&a ...

Ensure that there is a predetermined search result displayed on the search page prior to the user initiating a search

After setting up a search page in nextjs and implementing the functionality to fetch data from a database (supabase), users now see a search bar upon landing on the page. However, as expected, no results are displayed until the user initiates a search. Th ...

What are the steps to stop the left alignment of header text?

As I'm working on designing a unique Markdown theme in CSS, I am currently facing some challenges with regards to the styling of headers. Specifically, the h1 header is styled as follows: h1 { border-top: 1px solid black; width: 10%; margin: 0 ...

Utilizing Inline Placement within Email Templates

Seeking assistance in finding an alternative method to achieve the desired functionality in an email template. Having trouble with inline position styling being removed. table { width: 80%; border-spacing: 0; } table tr td.label-dots { positio ...

Display elements that are positioned absolutely within a container with scrolling overflow

My modal contains a scrollable list with many items that have absolute positioned elements causing overflow within the modal. How can I ensure that the absolute positioned elements are visible in this scenario? .modal { width: 300px; border: 1px ...

What are some solutions for resolving NextJS enoent issue?

Does anyone have an idea of what might be causing this error? Any help would be greatly appreciated. This error suddenly appeared and I can't seem to figure out the reason behind it. None of the sources I checked related to this topic, such as npm cle ...

Matching an element that contains a specific string in JS/CSS

I'm currently faced with an HTML file that's being generated by an outdated system, making it tricky for me to control the code generation process. The structure of the HTML code is as follows: <table cellpadding=10> <tr> ...

Steps to establish the starting value as 'Concealed'

I stumbled upon this interesting example that demonstrates how to create expandable/collapsible text when clicked. My question is, how can I initially set the value to be hidden so that the paragraph starts off collapsed and expands only when clicked? He ...

A guide on switching font family based on locale changes (language in i18n) within Next.js

My application supports multiple languages and allows users to switch between two languages using a select input. Additionally, I want to change the font-family based on the selected language. In my _app.js file: const {locale} = useRouter(); useEffect(() ...