Struggling to resize my icon correctly using tailwindCSS and Next.js with TypeScript

I've hit a roadblock with an issue that's been driving me crazy. I attempted to follow a tutorial on tailwindcss with next.js from YouTube. The goal was to utilize the heroicon library to create a stylish header with an icon. However, the icon I'm using appears much larger than it should be and I'm struggling to find a solution.

Below is my code:

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "preserveSymlinks": true,
    "experimentalDecorators": true,
    "noImplicitAny": true,
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

Header.tsx

import {TerminalIcon} from '@heroicons/react/outline'

const Header = () => {
    return (
        <header className='border-b border-gray-100'>
            <div className='container mx-auto px-4 sm:px-6 py-4'>
                {/* logo */}
                <p className='flex items-center space-x-1 text-blue-600'>
                    <TerminalIcon className='w-8 h-8 flex-shrink-0' />
                    <span className='font-bold text-lg tracking-tight whitespace-nowrap'>
                        Blog for dev
                    </span>
                </p>
            </div>
        </header>
    );
};

export default Header;

Footer.tsx

const Footer = () => (
    <footer className="px-4 sm:px-6 py-6 mt-24">
        <p className="text-center text-sm text-gray-500">
            2020 Better Dev. All rights reserved.
        </p>
    </footer>
);

    
export default Footer;

Layout.tsx

import Header from './Header';
import Footer from './Footer';
import React, {FC} from 'react';

interface Props {

}

const Layout: FC<Props> = ({ children, ...props }) => {
    return (
        <div className='min-h-screen flex flex-col'>
            <Header />
            <main className='flex-grow container mx-auto px-4 sm:px-6'{...props}>
                {children}
            </main>
            <Footer />
        </div>
    );
};

export default Layout;

index.tsx

import type { NextPage } from 'next'
import Head from 'next/head'
import Layout from '../sections/Layout'

const Home: NextPage = () => {
  return (
    <>
      <Head>
        <title>Home</title>
        <link rel='icon' href='/favicon.ico' />
      </Head>
      <Layout>
        {/* hero section */}
        <section className='flex flex-col justify-center items-center space-y-10 mt-12 sm:mt-24 md:mt-32'>
          {/* HeadLines */}
          <div className='space-y-4 max-w-4xl mx-auto text-center'>
            <h1 className='text-4xl sm:text-7xl font-bold capitalize'>
              <span className='block'>The dev platform</span>
              <span className='block'> for developers</span>
            </h1>
            <h2 className='text-xl sm:text-2xl'>
              Star your dev platform and share your knowledge!
            </h2>
          </div>
          <button
            type='button'
            className='bg-blue-500 hover:bg-blue-700 text-white font-bold py-6 px-3 rounded-md border-2 border-blue-600 hover:border-blue-700 text-lg sm:text-xl focus:outline-none focus:ring-4 focus:ring-blue-600 focus:ring-opacity-50 whitespace-nowrap'
          >
            Get started
          </button>
        </section>
     </Layout>
   </>
  )
}

export default Home

global.css

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  body {
    @apply bg-gray-50 text-gray-900;
    @apply min-h-screen;
  }
  ::selection {
    @apply text-white bg-blue-600;
  }
}

See current output here

Desired output can be viewed here

I seem to have gone wrong somewhere, despite meticulously following the tutorial step-by-step. The only difference is that my next.js project uses TypeScript. The attribute in

<TerminalIcon className='w-8 h-8 flex-shrink-0'>
was intended to rectify this, but hasn't worked. Additionally, the text color isn't behaving as expected. Any assistance would be greatly appreciated.

If you'd like to troubleshoot, here's the link to the repository:

https://github.com/jabandersnatch/landing_page

To see the issue firsthand, the repository has been deployed on Vercel at this link:

Lastly, here's the tutorial I was following:

https://www.youtube.com/watch?v=ijs2ORbwqok&t=117s

P.S: Apologies if my explanation of the issue isn't clear enough. This is my first time posting on Stack Overflow.

Answer №1

It's not necessary to distribute your tailwind.config.js file within the components folder.

An easy fix is to adjust the content key value in the tailwind.config.js to accommodate your file extensions. See an example below:

Contents of tailwind.config.js file

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

In this example, I have included file types such as: html, js, jsx, ts, tsx. You can add other file types that require tailwind configuration.

Answer №2

Good news - I have successfully resolved the issue! It turns out that the root cause was located within my tailwindcss.config.js file. Due to differences in my project structure compared to the tutorial, I encountered this problem.

├───pages
│   └───api
├───public
├───src
│   ├───components
│   │   ├───footer
│   │   ├───header
│   │   ├───layout
│   │   └───Navigation
│   └───redux
└───styles

Upon this realization, I identified that my module.exports configuration would not function as expected, as my components were situated in src/components. By simply updating the correct file path, everything is now operating smoothly!

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

Understanding the concept of event bubbling through the use of querySelector

I am currently working on implementing an event listener that filters out specific clicks within a container. For instance, in the code snippet below I am filtering out clicks on elements with the class UL.head. <div> <ul class="head"> < ...

The Highchart data series seems to be getting cut off

Can anyone assist me in creating a 24-hour data chart using Highcharts? I am encountering an issue where the first two data points are not rendering correctly, showing 11 columns instead of 12. I have provided an example here. Any help would be greatly a ...

What could be the reason for the lack of impact when assigning a [dateClass] in mat-calendar?

I've been trying to customize the appearance of specific days in the mat-calendar component from Angular Material, but I'm having trouble getting it to work. I discovered the dateClass property which seemed like the right solution, but no matter ...

MapBox notifies when all map tiles have finished loading

Currently, I am utilizing the Mapbox GL JS API to manipulate a Mapbox map. Prior to sending my result (which is a canvas.toDataURL) to the server via HTTP, I must resize my map to a larger resolution and then use fitbounds to return to the original points. ...

PHP not compatible with Fancybox iframe

I'm facing a simple problem that I can't seem to figure out. I have a button that, when clicked, opens a fancybox with an iframe displaying a page from my website. This page includes a form for sending an email. Everything works fine except that ...

Converting a React Typescript project to Javascript ES5: A step-by-step guide

I have a react typescript project and I need to convert the source code (NOT THE BUILD) to ES3 or ES5 JavaScript. This is because I want to use this code as a component in another React app. Can you suggest which preset and plugins I should use for this t ...

Implementing class toggling in AngularJS with ng-class

Trying to change the class of an element with ng-class <button class="btn"> <i ng-class="{(isAutoScroll()) ? 'icon-autoscroll' : 'icon-autoscroll-disabled'}"></i> </button> isAutoScroll(): $scope.isAutoScrol ...

streamlining form updates in vue

The code snippet provided is functional but unnecessarily complicated and lengthy. I am seeking a more efficient approach to achieve the desired outcome. <h6><label for="number">Change Number</label></h6> ...

Exploring the return type of the `within` function in TypeScript Library

I have helpers set up for my React tests using the testing library: const getSomething = (name: string, container: Screen | any = screen) { return container.getByRole('someRole', { name: name }) } The container can be either the default screen ...

Substitute form input loading

Question: <input id="id_sf-0-use_incident_energy_guess" name="sf-0-use_incident_energy_guess" onchange="show_hide_guess(this.id);" onload="show_hide_guess(this.id);" type="checkbox"> The issue lies with the onload event not working in input fie ...

What is the process for sending a file to the server using JavaScript?

It seems like the process is not as simple as I originally thought. Here is the breakdown of what I am trying to achieve: I am capturing the FileList in my state like this... const [formValues, setFormValues] = useState({ image: null }) <input typ ...

Puppeteer exhibiting unexpected behavior compared to the Developer Console

My goal is to extract the title of the page using Puppeteer from the following URL: Here's the code snippet I am working with: (async () => { const browser = await puppet.launch({ headless: true }); const page = a ...

Using `publishReplay()` and `refCount()` in Angular does not behave as anticipated when dealing with subscriptions across multiple components

I am currently investigating the functionality of publishReplay in rxjs. I have encountered an example where it behaves as expected: const source = new Subject() const sourceWrapper = source.pipe( publishReplay(1), refCount() ) const subscribeTest1 = ...

Can you provide guidance on implementing Material-UI's `withStyles` decorator in a practical scenario?

I'm currently solving the challenge of annotating the types for the different styles in my code. After converting from plain JavaScript to TypeScript, I am now adding type annotations. Here is a snippet of the code: import * as React from 'react ...

What are the steps to modifying the material characteristics of a model loaded using OBJ + MTLLoader?

After successfully loading an .obj model along with its corresponding .mtl file to correctly map the materials onto the model, I noticed that the loaded model appears very dark. To brighten it up, I attempted to change the emissive color to white but encou ...

Encountering an error in React Native: Unable to access property 'length' as it is

Currently, I am working on developing a registration application and I have encountered some issues in the final phases when attempting to submit the new data to the server. Below is the script I am using: import React from 'react'; import React ...

Implementing a boolean toggle method in Typescript for a class property

Hello there, fellow programmers! I am interested in changing the value of a class field using a method. I have a button in Angular that, when clicked, triggers the onSave() method: export class CourseComponent { isActive:boolean; onSave() { ...

Animating the Bookmark Star with CSS: A Step-by-Step Guide

I found this interesting piece of code: let animation = document.getElementById('fave'); animation.addEventListener('click', function() { $(animation).toggleClass('animate'); }); .fave { width: 70px; height: 50px; p ...

Issues arise with the escape key functionality when attempting to close an Angular modal

I have a component called Escrituracao that handles a client's billing information. It utilizes a mat-table to display all the necessary data. When creating a new bill, a modal window, known as CadastrarLancamentoComponent, is opened: openModalLancame ...

"Utilize Angular's $http module to execute a POST request for

Hey everyone, I'm a beginner with AngularJS and I've run into a problem while working on my project. I encountered this error: ReferenceError: $http is not defined when attempting to utilize the following code: 'use strict'; ...