What is the best way to format the content with Tailwind CSS?

I have been trying to customize the appearance of my header item container, which includes a home icon. The issue I'm facing is that despite styling the icon and other elements within the container using Tailwind CSS classes, the changes are not reflected on the webpage. I suspect it might be a problem with Tailwind CSS configuration, but I haven't been able to pinpoint the exact cause.

Below is the code snippet for Header.js:

import {
    BadgeCheckIcon,
    CollectionIcon,
    HomeIcon,
    LightningBoltIcon,
    SearchIcon,
    UserIcon,
} from "@heroicons/react/24/outline";
import Image from "next/image";
import HeaderItem from "./HeaderItem";

function Header() {
  return (
    <header className="">
        <div>
            {/* This is for icons that i'm using on the components section */}
            <HeaderItem title ='HOME' Icon = {HomeIcon}/>
        </div>
        {/* This is the logo image we are going to add in header component */}
        <Image
            className="object-contain"
            src='/images/hulu.png' 
            width={200} 
            height={100}
        />
    </header>
  )
}

export default Header

and this is HeaderItem.js

function HeaderItem({ Icon, title }) {
  return (
    <div>
        <Icon className='h-8 mb-1'/>
        <p className="opacity-0 hover:opacity-100 tracking-widest">{title}</p>
    </div>
  );
}

export default HeaderItem;

This is my tailwind.config.js file

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
    "./src/components/**/*.{js,ts,jsx,tsx,mdx}",
    "./src/app/**/*.{js,ts,jsx,tsx,mdx}",
  ],
  theme: {
    extend: {
      colors: {
        background: "var(--background)",
        foreground: "var(--foreground)",
      },
    },
  },
  plugins: [],
};

Despite configuring my styles using Tailwind CSS, there seems to be an issue with reflecting these changes on the webpage.

https://i.sstatic.net/EDYb2DMZ.png

Answer №1

Ensure to include the Icon prop when passing it to HeaderItem in JSX format:

...
<HeaderItem title ='HOME' Icon ={<HomeIcon className='h-8 mb-1'/>}/>
...

Then, you can access and utilize the passed prop within HeaderItem like this:

function HeaderItem({ Icon, title }) {
  return (
    <div>
        {Icon}
        <p className="opacity-0 hover:opacity-100 tracking-widest">{title}</p>
    </div>
  );
}

The HomeIcon serves as a reference, while <HomeIcon/> represents its specific instance.

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

Enhancing the WheelPicker feature in React Native JS by adding a string in front of a specific selected item

I am having an issue with adding the '$' sign before the selected WheelPicker item only. Currently, my code is adding the '$' sign in front of all Picker items. How can I resolve this problem? Thank you for any assistance. https://i.sst ...

How to Align Bootstrap Buttons in a Row with Varying Text Lengths

-Salutations, Universe!- I am currently engaged in a Bootstrap 4 project and I have encountered a hurdle. Here is the snippet of code that has posed a challenge. Currently, the buttons are positioned right up against the text. My aim is to align them to ...

Displaying Component when Clicked using Vue.js

How can I display a modal component after an "on click" event? Is it possible to show a component using a method call, or what is the recommended approach in this scenario? Here is my specific use case: I have multiple cards each containing various infor ...

Stuck with the same icon even after a successful AJAX call

I am currently working on implementing a 'add to my list' function in my web app. The goal is to change the color of an icon when a user clicks on it, after sending the necessary data to the server. Despite successfully sending the data to the s ...

When a user manually updates an input, only then will the jQuery change event be triggered

Is it possible to differentiate between user-initiated changes and manual modifications in JavaScript? $('#item').change(function() { alert('changed!'); }); There are times when I need to trigger the change event artificially wit ...

Navigating JQuery's Append and After functions can be a challenge

Struggling to make my simple input line append whatever is entered when the OK button is pushed. Despite trying various methods, I can't seem to get it working properly. HTML: <p> <input name="todo" id="todo" type="text" value="Set Me To Val ...

Minimize the quantity of files processed by Vue

Here is the content of my vue.config.js file: css: { extract: false, }, configureWebpack: { devtool: 'source-map', optimization: { splitChunks: false, }, }, productionSourceMap: false, I'm facing an issue where running npm run b ...

Problem encountered when trying to generate a custom-shaped div with a width set to 100

I am currently working on creating a diagonal div at the bottom of another div. I want it to have a design similar to this: . I encountered an issue when I tried adding a 100vw value to my border-left, as it caused a horizontal scrollbar to appear on my w ...

Selectize Fails to Populate Options Using Ajax

ExpressJS is the platform I am using to develop a management dashboard for a community project. Right now, my main concern is integrating a modal that allows users to add new games to a database. Although I am able to fetch data remotely, I am facing diffi ...

The issue of infinite rendering caused by useState and how to effectively resolve it

I'm facing a strange issue in just a few lines of code, and I can't quite figure out what's happening behind the scenes. Here are the 4 lines causing trouble: function FarmerComponent(props) { let authCtx = useContext(AuthContext) let u ...

Streaming with RTSP or RTP on an HTML5 platform

I am currently developing a web application that needs to play an RTSP/RTP stream from a server . Is it possible for the HTML5 video/audio tag to support rtsp or rtp streams? If not, what alternative solutions are available? Would integrating a VLC plugin ...

Why do Next.Js applications remain static even after pre-rendering?

In my professional experience, I have been utilizing React and Next.Js. Recently, a junior colleague posed an interesting question regarding the difference between traditional websites that used to reload due to fetching all HTML and CSS files from the ser ...

Scrolling through image galleries with automatic thumbnails

I am looking to create an automatic image scrolling feature on my webpage using a bunch of images I have. I have searched for a solution but have not found one that fits my requirements. I don't think a carousel is the right approach for this. The sol ...

Accessing MongoDB documents that are just 24 hours old

Currently, I am attempting to retrieve the previous day's documents from MongoDB by utilizing a bash script along with JavaScript. I have successfully employed JS to send the query to MongoDB. However, I encountered an issue when handling the date fo ...

Utilizing AWS Amplify to access detailed owner information beyond just their ID

Is it feasible to achieve something like this? How should the design be tailored for this specific use case? Do I need to incorporate a lambda function that includes the user (owner) in the post creation process? Seeking assistance on how to implement thi ...

In JavaScript, the return statement is used to halt the execution of any subsequent statements

I encountered a situation where I need to stop the execution of the next function call if the previous function has a return statement. However, I noticed that even though there is a return statement in the "b" function below, the next function call still ...

Nested UL elements within a loop

I'm currently facing a challenge with a nested UL structure. It's a dropdown menu generated using a foreach loop. Below is the HTML code snippet: <ul> <li class='a1'>Menu <ul class="sub"><li>Sub 1&l ...

SSG pages in NextJS with case-insensitive routes

Currently, I am utilizing NextJS for converting a CSV file of information into static pages. Each page corresponds to pages/[slug].jsx. Within the [slug].jsx functions getStaticPaths() and getStaticProps(), I am applying toLowerCase() on the slug value to ...

Troubleshooting issue with jQuery datepicker not triggering onselect event

Query Function: $(function() { $("#iDate").datepicker({ dateFormat: 'dd MM yy', beforeShowDay: unavailable onSelect: function (dateText, inst) { $('#frmDate').submit(); } }); }); HTML ...

Ways to determine the visibility status of an HTML tag in Angular 2

Is there a way to check if a div is hidden in Angular 2? ...