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>
    </>

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>

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

The returned response from GraphQL is displaying [Object] instead of the expected data

Recently delving into GraphQL and utilizing it to fetch data from the Wordpress API. While crafting a query in the GraphiQL Wordpress IDE, the data is displayed correctly. However, upon integrating the query into my NEXTJS application and logging the resul ...

Ajax displays JSON data within an array format

Looking for a solution where I have MySQL data displayed in a table, with each row having a button. When the button is clicked, a bootstrap modal should appear containing that data. I have converted the MySQL data to JSON format and assigned the ".view_dat ...

Restricting the npm react-date-picker to display only the most recent 30 days dynamically in a React app

I need to set up a npm react-date-picker in my React project to show only the dates from the last 30 days starting from today. Additionally, I want to disable future dates starting tomorrow. import DatePicker from "react-date-picker"; <DateP ...

Discovering a Match within a JavaScript Object and Array with the help of Jquery's Each

I am currently working on implementing an array of filters to search through a JavaScript object containing store locations. My goal is to find a full match using both filters from the filters array, which currently has 2 items but will eventually have mor ...

Issue: Trouble with ajax form functionality

I'm a beginner in ajax, js, and php. Recently, I set up a simple contact form. <form id="contact-form" method="post" action="process.php" role="form"> <div class="messages"></div> <div class="form-group"> <l ...

Generating a sequential array of dates and times in Angular

Currently, I am working on implementing a feature that will allow users to see the available visit times between two dates they select, specifically from 8:00 to 17:00 every day. For instance: If a user selects 1 Sep to 4 Sep, the system should return [1. ...

Utilizing Bootstrap for Centering Content Vertically and Horizontally

My login form is designed with a simple layout using Bootstrap 3.3.7 and a wrapper class div. However, when viewed on a full browser screen, the text boxes overlap the labels. How can I adjust it so that the default bootstrap behavior is applied to the for ...

angular 2 checkbox for selecting multiple items at once

Issue I have been searching for solutions to my problem with no luck. I have a table containing multiple rows, each row having a checkbox. I am trying to implement a "select all" and "deselect all" functionality for these checkboxes. Below is an example o ...

javascript ondrag while self-pressing

Within this div, I have a series of p elements. My goal is to drag the selected element into the input field. Here's an example: var input = document.getElementById("test"); input.addEventListener('drop', function (event) { event.pr ...

Having trouble with CSS margins behaving unexpectedly

Could someone please explain why I am unable to add margin-top/bottom or padding-top/bottom to this "a" tag? I am trying to center "Konoha" in the header box. html{ background-color: white } body{ width: 88.5%; height: 1200px; margin: 0 auto; borde ...

The issue with importing data into Google Sheets due to an error with Ljava

After combining different scripts, I am struggling to properly input data into the code. Email Input: *Status:* *Date:* 03/31/2020 *WorkOrder:* 123456-1 *DMSShipDate:* 03/31/2020 *PONumber:* 8675309 *Company:* Test New Script var ui = SpreadsheetApp.g ...

Specify the input type to occupy the full width and be contained within its parent div

I'm currently dealing with a form that includes input fields for email and password, along with some additional buttons. Here is the HTML code: <div id="login-form"> <form> <input type="email" placeholder="Email" id="email" name= ...

Encase a group of child elements within a parent container using

Currently, I am able to wrap an entire li-element in an ordered list with a link: $(e).wrap('<a href="#" onclick="window.open(\'/xyz/\');return false;"></a>'); This is the HTML construct: <li class=""> ...

Using a for loop to render components in React

    I am attempting to create 9 buttons by setting x=3 and y=3 within a for loop in my render button method. However, I am facing an issue where the buttons are not being rendered correctly. When I use console.log, it shows that the rendering is happeni ...

What is the process by which node.js synchronously delivers a response to a REST web service?

Sorry if this question seems obvious! I'm struggling to grasp how node.js handles requests from the browser. I've looked at tutorials online where express.js was used to create the server-side code with node.js. Routes were then set up using prom ...

Tips for creating the appearance of a resizable element

My goal was to replicate the resizing and moving functionality of elements in Adobe Illustrator using CSS alone. Unfortunately, I couldn't find any useful resources on how to achieve this. ...

In order for styling to be applied in Storybook, the default Ant Design component must be exported

I want to create React Components using Ant Design and showcase them in Storybook. Both the components and storybook are functioning correctly as expected. modal.stories.js import React from "react"; import { action } from "@storybook/addon-actions"; im ...

Preventing Banner Images from Covering Side Carts in E-commerce Stories - Tips and Tricks

I'm encountering an issue with the side cart and suspect that my CSS is to blame. Can you assist me in resolving this problem? The webpage has a background image—a full-width banner. However, when I open the side cart, the image overlaps it, concea ...

Using MUI-X autocomplete with TextField disables the ability to edit cells

When I double-click on a cell, everything works fine. However, after the second click to start editing the textfield, the cell stops editing. I can still choose an option though, so I believe the issue lies somewhere in the textField component, possibly i ...

Sequence of HTML elements arranged in a stack

Recently, I came across a useful jQuery tutorial called "jQuery for Absolute Beginners: Day 8". In this tutorial, there is an interesting code snippet that caught my attention: $(function() { $('.wrap').hover(function() { $(this).childre ...