Next.js Discord

Discord Forum

Need help with positioning of elements

Answered
Abert's Towhee posted this in #help-forum
Open in Discord
Abert's TowheeOP
Any reason for the { children } being above the <Navbar /> component? Please look at the attached code & image.

Layout File:
import './globals.css'
import { Navbar } from '@/components'

export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <body>
        <Navbar />
        {children}
        </body>
    </html>
  )
}


Navbar File:
import Image from "next/image"
import Link from "next/link"
import { Rubik } from "next/font/google"
import SearchBar from "./SearchBar"
import CustomBtn from "./CustomBtn"

const RubikFont = Rubik({ subsets: ['latin']})

const Navbar = () => {
  return (
    <header className="w-full absolute z-10">
      <nav className={`bg-[#1A1A1A] max-w-[1440px] mx-auto w-full flex flex-col sm:flex-row justify-between items-center px-16 py-4 text-white ${RubikFont.className}
      `}>
        <div className="flex items-center space-x-4">
          <Link href="/">
            <span>
              <Image src="/logo.svg" width={140} height={40} alt="logo" />
            </span>
          </Link>
        </div>
        <div>
          <ul className="flex items-center space-x-8">
            <li>
              <SearchBar />
            </li>
            <li>
              <Link href="/login">
                <CustomBtn />
              </Link>
            </li>
          </ul>
        </div>
      </nav>
    </header>
  )
}

export default Navbar
Answered by Rafael Almeida
the header inside Navbar is absolutely positioned so it will be above all elements: https://developer.mozilla.org/en-US/docs/Web/CSS/position#absolute
View full answer

4 Replies

Abert's TowheeOP
hello?
the header inside Navbar is absolutely positioned so it will be above all elements: https://developer.mozilla.org/en-US/docs/Web/CSS/position#absolute
Answer
it is basically removed from the normal elements flow