Cant get sidemenu button to be sticky

I need assistance in making the component within my grid sticky, i am using tailwindcss react/nextjs. The “back button” is just a button, the “footer” is just my name and the {children} element is a two screen tall wall of text.
Layout component, wrapping page.tsx:

import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import Footer from "@/components/ui/Footer";
import BackButton from "@/components/ui/BackButton";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
  title: "title",
  description: "desc",
};

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en">
      <body className={inter.className}>
        <div className="md:grid md:grid-cols-[1fr_50%_1fr] md:w-full mx-auto my-10 md:my-0 sm:w-4/6 w-5/6 flex flex-col gap-6 justify-center">
          <div className="flex flex-col items-start md:justify-start md:items-center md:mt-[200px] bg-blue-600">
            <div className="md:sticky bg-red-400 md:top-0">
              <BackButton />
            </div>
          </div>

          <div className="justify-center bg-green-700 items-center md:wrapper-div transition-all duration-500">
            {children}
            <Footer />
          </div>
        </div>
      </body>
    </html>
  );
}

Page.tsx is just a wall of text 200vh tall.

this is a snippet of my code found in layout on my react/nextjs app, i am using tailwind, can someone help me with why my back button is not working as intended? (it is meant to be position sticky)

I Have tried various solutions and asked chat gpt but to no avail.

5

The sticky class requires that the element’s parent container doesn’t interfere with the sticky behavior, which could happen if there’s no space for the element to scroll within or if the layout creates unexpected behavior.

In your case, the grid layout might be causing issues, especially the way flex, grid, and sticky behave together.

You may try to adjust your layout as:

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en">
      <body className={inter.className}>
        <div className="md:grid md:grid-cols-[1fr_50%_1fr] md:w-full mx-auto my-10 md:my-0 sm:w-4/6 w-5/6 gap-6 justify-center">
          <div className="md:flex flex-col items-start md:items-center bg-blue-600">
            <div className="md:sticky md:top-[100px] bg-red-400">
              <BackButton />
            </div>
          </div>

          <div className="bg-green-700 transition-all duration-500">
            {children}
            <Footer />
          </div>
        </div>
      </body>
    </html>
  );
}

where following three adjustments have been made:

  1. Moved the sticky class directly on the element holding the BackButton and ensured md:top-[100px] sets the top sticky distance correctly.
  2. Removed unnecessary flex classes in the outer containers that could interfere with the layout.
  3. The sticky element is now inside a simpler flex container, which should avoid conflicts with grid layout behavior.

As a side note:

  • sticky only works if there’s enough scrollable content. Make sure your children content is large enough (it seems like you have a 200vh tall element, so that should work).
  • ensure that nothing breaks scroll behavior. If you are using overflow: hidden or something similar on parent containers, it can prevent sticky from working properly.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật