#Root元素的反应功能组件中的内联样式

发布于 2025-01-18 13:56:07 字数 270 浏览 5 评论 0原文

我创建了一个React功能组件,在其中附上了一个侦听器以滚动。我已经观察到,此事件侦听器需要使用ID =“ root”的元素附加到此类元素 - document.getElementById(“ root”)。当前,我有一个分开的CSS文件,可以将样式应用于我的组件专门为卷轴。 CSS样式表有一个单一类#root我提供growflow-y:scroll,以便滚动正确地发生。 但是现在,我希望在我的反应功能组件中获得这种样式。怎么办?

I have created a React functional component where I have attached an event listener for scrolling. I have observed that this event listener needs to be attached to the element with ID = "root" i.e something of this sort - document.getElementById("root"). Currently, I have a seperate CSS file to apply the styling to my component specifically for the scrollbar. The CSS stylesheet has a single class #root where I provide overflow-y: scroll, so that scrolling happens properly.
But now, I wish to get this styling within my React functional component. How can this be done ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文