Smooth Scrolling Issues (CSS)

Hey there pals. I am trying to get smooth scrolling added to ONE element on a page, not the entire HTML document. I can get the entire HTML document to smooth scroll, but for some reason I cannot do this for just one element.

Here’s the PEN: You’ll see I added the class to every element just to see if this would cause smooth scrolling, and it does not. If I change the class to HTML, it smooth scrolls fine.

Are we not able to add smooth scrolling to just ONE hyperlink/element?

PEN:: https://codepen.io/brittany-golden/pen/bXqXOp

The element your applying smooth scrolling to has to be able to scroll on its own, like the HTML document does.

Have you tried a simple test case with overflow auto to see that element only scrolling.


<!DOCTYPE HTML>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Test Page</title>
<style>
.smooth-scrolling {
  scroll-behavior: smooth;
  width:50%;
  height:200px;
  overflow:auto;
  border:1px solid;
}
</style>

</head>
<body>

<div class="smooth-scrolling">
  <p>sample text</p>
  <p>sample text</p>
  <p>sample text</p>
  <p>sample text</p>
  <p>sample text</p>
  <p>sample text</p>
  <p>sample text</p>
  <p>sample text</p>
  <p>sample text</p>
  <p>sample text</p>
</div>

</body>
</html>

I keep smooth scrolling set in my browser settings so I see it scrolling smooth anyways.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.