1

So, I have this code:

    <div className="bg-black font-serif pl-20 grid text-white !scroll-smooth">
      <Head>
        <title>MinimDays | Ultimate minimalism</title>
        <link rel="icon" href="/plant.ico" className="fill-white" />
      </Head>
      <section id="home">
        <div className="flex">
          <span className="pt-72 mr-[400px]">
            <h1 className="text-3xl ">MinimDays | Ultimate minimalism</h1>
            <Link href="#about"><a className="text-lg hover:text-gray-400">About</a></Link> |
            <Link href="#contactus"><a className="text-lg hover:text-gray-400"> Contact Us</a></Link>
          </span>
          <picture>
            <img src="/photo.jpg" alt="photo" className="h-[480px] w-[320px] mt-[80px] rounded-xl border-white border-4"/>
          </picture>
        </div>
      </section>
      <section id="about" className="mt-20">
        <h1 className="text-3xl mb-5">About Us</h1>
        <hr className="mb-5"/>
        <p className="text-lg">I like the idea of digital minimalism, but apps that satisfy this category are usually paid <br /> or have a free tier which is highly limited, so I said SCREW IT, <br /> and created my own! </p>
      </section>
    </div>

And the scroll animation does not work. I tried on Firefox Developer Edition and Chrome, but nothing seems to help. Any suggestions?

5
  • Why there is an apostrophe before this class !scroll-smooth? Try removing this ! Commented Sep 16, 2022 at 17:06
  • 1
    There is no apostrophe, the exclamation mark is just to indicate important Commented Sep 16, 2022 at 17:07
  • Nice I discovered another thing thanks. I didn't found any issues here and I hope you already tried running this in incognito and Ctrl + F5 already used Commented Sep 16, 2022 at 17:09
  • At first glance I thought this was the magical fix, but sorrowfully I didn't work :( Commented Sep 16, 2022 at 17:13
  • If you haven't see this yet give it a try stackoverflow.com/questions/71129698/… Commented Sep 16, 2022 at 17:24

2 Answers 2

1

You need to add smooth-scroll to the html element. So add this to your main css file:

html {
  scroll-behavior: smooth;
}

I managed to get smooth scrolling working with your example code with the above change, in an HTML version that I put together.

I haven't tested it in Next.js, but note the <Link /> is for navigation between pages. Not sure if that will cause problems for links within the page.

MDN Smooth Scroll documentation:

When this property is specified on the root element, it applies to the viewport instead. This property specified on the body element will not propagate to the viewport.

https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-behavior

Sign up to request clarification or add additional context in comments.

Comments

0

I was using Link component from Next.js and it is not working with scroll-smooth, only working with tag.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.