Is there a way to dynamically change the overflow style for the html and body elements based on the page being viewed?
For instance, on the about page, I want to hide overflow for html but not for body, whereas on the contact page, I want to hide overflow for body but not for html.
This issue arose when I switched from using vanilla CSS to the Next UI library halfway through the project. I am looking for a quick solution, even if it involves a bit of a hack.
Here is an example of some pseudocode I have tried:
<Html lang="en" style={if (aboutpage) { overflow: "hidden" } else { overflow: "scroll" }}>
<Head>{CssBaseline.flush()}</Head>
import React from 'react';
import Document, { Html, Head, Main, NextScript } from 'next/document';
import { CssBaseline } from '@nextui-org/react';
import { useRouter } from "next/router";
class MyDocument extends Document {
static async getInitialProps(ctx) {
const initialProps = await Document.getInitialProps(ctx);
return {
...initialProps,
styles: React.Children.toArray([initialProps.styles])
};
}
render() {
return (
<Html lang="en" style={{ overflow: 'scroll' }}>
<Head>{CssBaseline.flush()}</Head>
<body style={{ overflow: 'hidden' }}>
<Main />
<NextScript />
</body>
</Html>
);
}
}
export default MyDocument;
Any suggestions or advice would be greatly appreciated!
I attempted to create some pseudocode, but I am struggling with implementing a conditional statement to change the style of the Html tag and Body element.