Troubles with NextJS and TailwindCSS Styling

I encountered a strange issue when I used the component separately. Here's how the code looked like:

    <>
      <Head>
        <title>Staycation | Home</title>
        <meta name="viewport" content="initial-scale=1.0, width=device-width" />
        <meta name="description" content="We provide what you need to enjoy your holiday with family. House, Villa, Resort booking administration." />
        <meta name="og:title" content="Staycation | Home" />
        <meta name="og:description" content="We provide what you need to enjoy your holiday with family. House, Villa, Resort booking administration." />
      </Head>
      <div className="min-h-screen">
        <NavbarComponent />
        <HeroSection />
        <MostPickedSection />
        <CategoriesSection />
        <TestimonialSection />
        <FooterComponent />
      </div>
    </>

https://i.sstatic.net/6L8qB.png

However, when I directly included the component without separating it, the results were good:

      <Head>
        <title>Staycation | Home</title>
        <meta name="viewport" content="initial-scale=1.0, width=device-width" />
        <meta name="description" content="We provide what you need to enjoy your holiday with family. House, Villa, Resort booking administration." />
        <meta name="og:title" content="Staycation | Home" />
        <meta name="og:description" content="We provide what you need to enjoy your holiday with family. House, Villa, Resort booking administration." />
      </Head>
      <div className="min-h-screen">
        <NavbarComponent />
        <div className="flex flex-col-reverse md:flex-row container-item mt-4 md:mt-16">
          <div className="flex flex-col justify-between flex-1">
            <div className="flex md:block flex-col items-center">
              <h1 className="mt-5 md:mt-0 font-bold text-center md:text-left text-2xl md:text-5xl text-primaryColor" style={{ lineHeight: '170%' }}>
                FORGOT BUSY WORK,
                <br />
                START NEXT VACATION
              </h1>
              <p className="w-4/5 md:w-2/5 mx-auto md:mx-0 mt-2 font-light text-center md:text-left text-xs md:text-base text-greyColor" style={{ lineHeight: '170%' }}>
                We provide what you need to enjoy your holiday with family. Time to make another memorable moments.
              </p>
              <button type="button" className="w-4/5 md:w-1/3 py-4 md:py-4 mt-3 md:mt-8 md:font-medium text-xs md:text-base rounded-md shadow-2xl transition-all duration-75 hover:opacity-80 text-whiteColor bg-secondaryColor">
                Show Me Now
              </button>
            </div>
            <div className="hidden md:flex justify-between items-center w-2/3">
              <HeroItem icon="/icons/Travellers.svg" title="10.203" description="Travellers" />
              <HeroItem icon="/icons/Treasures.svg" title="781" description="Treasures" />
              <HeroItem icon="/icons/Cities.svg" title="1.492" description="Cities" />
            </div>
          </div>
          <div className="flex justify-end flex-1">
            <img src="../images/Hero.png" alt="Hero" className="w-full md:w-4/5 mt-2 md:mt-0" />
          </div>
        </div>
        <MostPickedSection />
        <CategoriesSection />
        <TestimonialSection />
        <FooterComponent />
      </div>

https://i.sstatic.net/szilo.png After changing the code back from the non-separated to separated components again (which resulted in a good outcome), I realized the significant difference.
I hope this clarifies the confusion I faced while working on this project.

Answer №1

I encountered a similar issue, but managed to resolve it (though I was working with React).

  1. Try changing the component extension from .jsx to .js

    or

  2. Alternatively, consider adding .jsx to your content in tailwind.config.js

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: ["./src/**/*.{html,js,jsx}"],
  theme: {
    extend: {},
  },
  plugins: [],
};

Answer №2

There could be a few reasons why the issue is arising:

  • You might need to reset the project for Tailwind to compile properly.
  • Ensure that your tailwind directives are included in the styles/globals.css file.
  • Check the tailwind.config.js file to confirm if the HeroSection component is listed within the specified paths in the contents array.

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

Oops! Looks like there's an issue with the type error: value.forEach is

I am working on creating an update form in Angular 6 using FormArray. Below is the code snippet I have in editfrom.TS : // Initialising FormArray valueIngrident = new FormArray([]); constructor(private brandService: BrandService, private PValueInfoSe ...

Struggling to get JavaScript to successfully load a .txt file in order to load various links

I created a cool feature that takes users to a random link, but I currently have a large list of links and wanted to find a way for JavaScript to read them from a text file. The code I have tried so far is not working, and I have experimented with other s ...

The art of integrating partial rendering into a template

I'm currently working on a project using Angular 2 and I need to display a partial inside a template without having to create a new component. Is this doable? import {Component} from 'angular2/core'; import {RouteConfig, ROUTER_DIRECTIVES} ...

Arranging sequence of jQuery functions

I have implemented a loop using jQuery that iterates through specific elements on an HTML page. During each iteration, I switch over a variable and add HTML code to particular locations. The issue arises when one of the appends requires importing another ...

Using Angular's async, you can retrieve a value returned by a promise

Within the library I am currently utilizing, there is a method called getToken which can be seen in the following example: getApplicationToken() { window.FirebasePlugin.getToken(function(token) { console.log('Received FCM token: ' + to ...

having difficulty choosing a particular identifier from a JSON string

I'm currently working on a project to create an admin page for managing client information. However, I've encountered an issue where I am unable to select the client's unique ID to display all of their information on a separate page. On the ...

Is there a way to determine if a chosen date and time are prior or subsequent to the current date and time in an AngularJS environment?

When using a datepicker and timepicker, I have obtained a selected date and time. Now, I need to determine if this selected date and time is before or after the current date and time. For example, if the selected date is "Sat Dec 12 2015" and the selected ...

Adjusting the Size of an HTML Slideshow

While designing a homepage for my band, I encountered an issue when trying to integrate a slideshow element from an external source. The size of the slideshow is fixed at 600 x 300px and cannot be adjusted. Additionally, I found it challenging to position ...

data is currently being uploaded to the storage, however, the grid is not displaying any

After loading JSON data into the store, I am unable to see any data in the grid. Can someone please point out what I might be doing wrong? Here's the code snippet for the grid: { xtype: 'gridpanel', ...

Discovering which versions of dependencies are compatible can be a breeze with just a

Having a lot of dependencies in node that haven't been updated regularly can lead to encountering numerous error messages like these. npm ERR! peerinvalid The package <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5022353 ...

Error: Attempting to access the 'scrollIntoView' property of a null object in React Table

const myModal =({conversations})=>{ const messagesEndRef = React.useRef(null); const scrollToBottom = () => { messagesEndRef.current.scrollIntoView({ behavior: "smooth" }); }; useEffect(() => { ...

Positioning pictures in front of a backdrop

I'm facing an issue with a section that slides into view with a blue background. I want to add a picture in the upper left corner, but it's barely visible and the blue background disappears. Here's a snippet of the HTML code: <header id ...

Utilizing Fragments in Vuejs 2.x with Jsx - A User's Guide

Considering the presence of Fragments in React and the lack of a specific solution in the official Vuejs GitHub thread, what alternative methods could be used in Vuejs? This information may be beneficial for developers transitioning from a React backgrou ...

Transforming a JavaScript object into a different shape

I need help converting a list of team objects containing team names, reporters, and statuses for each day into date-based objects with all teams and their respective statuses for each date. I attempted the following code snippet but did not achieve the de ...

Is there a way to incorporate the information from PHP files into the output produced by JavaScript?

I am currently working on a JavaScript script that scrapes data and displays the result on the screen successfully. However, I now face a challenge in wrapping this output with pre and post content from PHP files for formatting purposes. Here is an overvi ...

Can JavaScript be used to dynamically assign events to elements on a webpage?

I am currently using the following code: if ( $.support.touch == true ) { $(window).on('orientationchange', function(event){ if ( full == false ) { self.hideAllPanels("7"); } }); } else { $(window).on(&apo ...

Having trouble with the express message! I can't seem to access the template I created

I am looking to receive a notification similar to an alert, as described in this link: https://github.com/visionmedia/express-messages By default, I receive something like this https://i.stack.imgur.com/9XlA9.png If I use a template, I do not get any out ...

What is preventing the "car" icon from moving along the designated "path" in an svg file?

When I click "next", the path changes color, but the "car" does not move. When I setState . However, if I setState in: const [position, setPosition] = useState('here!!! I set position') The car moves. What could be the problem? Unfortunately ...

Tips for ensuring the Search button always remains alongside the input bar during resizing with percentages

I've been trying to figure out why the search button is still showing at the bottom left and creating an "l" shape even though I'm using style="overflow: hidden; padding-right: .5em;". Does anyone have any ideas as to what might be causing this i ...

What is the process for modifying a task on my to-do list with a long press?

I'm currently working on implementing a task update feature in my project. However, I've encountered an issue where the prompt only works in the browser environment. Is there a way to make this work in React Native or are there any alternative so ...