I recently started exploring nextjs and came across this video
"https://www.youtube.com/watch?v=KzqNLDMSdMc&ab_channel=TheBraveCoders"
This is when I realized that the CSS styles were not being applied to HeaderTop (the first component created)
HeaderTop
import React from "react";
import { BsFacebook, BsTwitter, BsInstagram, BsLinkedin } from "react-icons/bs";
const HeaderTop = () => {
return (
<div className="border-b border-gray-200 hidden sm:block">
<div className="container py-4">
<div className="flex justify-between items-center">
<div className="hidden lg:flex gap-1">
<div className="header_top__icon_wrapper">
<BsFacebook />
</div>
<div className="header_top__icon_wrapper">
<BsTwitter />
</div>
<div className="header_top__icon_wrapper">
<BsInstagram />
</div>
<div className="header_top__icon_wrapper">
<BsLinkedin />
</div>
</div>
<div className="text-gray-500 text-[12px]">
<b>FREE SHIPPING</b> THIS WEEK ORDER OVER - $55
</div>
<div className="flex gap-4">
<select
className="text-gray-500 text-[12px] w-[70px]"
name="currency"
id="currency"
>
<option value="USD $">USD $</option>
<option value="EUR €">EUR €</option>
<option value="INR">INR</option>
</select>
<select
className="text-gray-500 text-[12px] w-[80px]"
name="language"
id="language"
>
<option value="English">English</option>
<option value="French">French</option>
</select>
</div>
</div>
</div>
</div>
);
};
export default HeaderTop;
localhost:3000/ ] (https://i.sstatic.net/w8uQ9.png)
These are the other files:
layout.tsx
import './globals.css'
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
import HeaderTop from '@/componenets/HeaderTop'
const inter = Inter({ subsets: ['latin'] })
export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body className={inter.className}>
<HeaderTop />
{children}
</body>
</html>
)
}
page.tsx
import Image from 'next/image'
import HeaderTop from '@/componenets/HeaderTop'
import HeaderMain from '@/componenets/HeaderMain'
export default function Home() {
return (
<main>
</main>
)
}
It works in the video, but starts working only when I copy the code from HeaderTop.tsx to page.tsx
page.tsx (After Edit)
import Image from 'next/image'
import { BsFacebook, BsTwitter, BsInstagram, BsLinkedin } from "react-icons/bs";
import HeaderTop from '@/componenets/HeaderTop'
import HeaderMain from '@/componenets/HeaderMain'
export default function Home() {
return (
<main>
<div className="border-b border-gray-200 hidden sm:block">
<div className="container py-4">
<div className="flex justify-between items-center">
<div className="hidden lg:flex gap-1">
<div className="header_top__icon_wrapper">
<BsFacebook />
</div>
<div className="header_top__icon_wrapper">
<BsTwitter />
</div>
<div className="header_top__icon_wrapper">
<BsInstagram />
</div>
<div className="header_top__icon_wrapper">
<BsLinkedin />
</div>
</div>
<div className="text-gray-500 text-[12px]">
<b>FREE SHIPPING</b> THIS WEEK ORDER OVER - $55
</div>
<div className="flex gap-4">
<select
className="text-gray-500 text-[12px] w-[70px]"
name="currency"
id="currency"
>
<option value="USD $">USD $</option>
<option value="EUR €">EUR €</option>
<option value="INR">INR</option>
</select>
<select
className="text-gray-500 text-[12px] w-[80px]"
name="language"
id="language"
>
<option value="English">English</option>
<option value="French">French</option>
</select>
</div>
</div>
</div>
</div>
</main>
)
}
After making this change, it continues to work fine. I have tested it on different browsers and it remains stable until any modification is made. If I restart, and the code is not present in page.tsx, it fails.
localhost:3000/ https://i.sstatic.net/Sdibf.png
Does anyone have an idea why this is happening and how can it be fixed? Here is the complete project:
https://github.com/AbdulMoqueet/shopping-web-app
I attempted changing browsers to rule out cache issues, but the problem persisted. I resorted to copying the code to page.tsx file, which provided a temporary fix as long as no classes were added.