Tips on enlarging a webpage without showing the scroll bar on the main component

My goal is to create a webpage that resembles a window application. However, I've encountered an issue where zooming in on the page results in a scroll bar appearing on the main page. The parameters for the main page (the parent) are set as follows: width: 100vw, height: 100vh

I'm looking for a solution to enable scrolling through the components inside the main page (the children components) instead of scrolling the main page itself (the parent component). Below is the CSS code snippet for my setup:

The initial CSS code for the main page (parent), styled using Material-ui, with 'root' as the className for the main page and 'header', 'breadCrumb', and 'content' as the classes for my children components.

const useStyles = makeStyles({

root: {
    width:'100vw',
    height: '100vh',
},

header: {
    height: '10%',
},

breadCrumb: {
    height: '10%',
},

content: {
    height: '80%',
}

Now, the 'content' component also contains its own children elements (sidebar and content) with their respective CSS properties outlined below:

const useStyles = makeStyles({

root: {
    border: '1px solid blue', 
    display: 'flex',
    width:'auto',
    height: 'auto',
},

sidebar: {
    backgroundColor: 'orange',
    width: '20%',

    height: 'auto',
    border: '1px solid red',
    overflow: 'scroll'
},

content: {
    height: 'auto',
    width: '80%',
}

If there's something crucial that I may have missed or if you have any suggestions to tackle this issue, please provide guidance. Any help would be greatly appreciated!

Answer №1

Typically, you should follow these steps ...

  1. Begin by styling your root element in the page (or higher container component) :

height: "100vh" -> this will completely fill the screen.

  1. Next, style the children components within that container :

so that some of their heights are 100%.

  1. Finally, ensure that each child component has the height set to:

height: '100%' -> in order to fit on the page.

Answer №2

If you are looking to hide the scroll bar while maintaining scrolling functionality, check out this helpful guide from w3schools: https://www.w3schools.com/howto/howto_css_hide_scrollbars.asp

 /* Hide scrollbar for Chrome, Safari and Opera */
.example::-webkit-scrollbar {
  display: none;
}

/* Hide scrollbar for IE, Edge and Firefox */
.example {
  -ms-overflow-style: none;  /* IE and Edge */
  scrollbar-width: none;  /* Firefox */
} 

You can implement this in your .root class (or in the html or body of your .css file) to hide the scrollbar on the root element or page when a user zooms in.

If you only want specific elements like your Content or Sidebar to scroll, you will need to set their height. Use values like auto, px, or vh.

For examples of how to hide the scrollbar at the page level but show it in certain elements like a Sidebar and Content section, check out this quick fiddle I created: https://jsfiddle.net/bethylogism/b6nuehqg/246/

If this doesn't quite address your issue, consider creating a JS Fiddle or CodePen showcasing the problem you're facing. This will make it easier for others to assist you. If you mention "the window application," providing more context would be helpful.

Answer №3

Fortunately, I was able to find a solution to the problem and will share it here.

My goal was to create a page where the main content does not scroll, but the components within it can be scrolled by zooming in. By setting the width and height of the main page to 100vw and 100vh, I could then specify the dimensions of the components inside using percentages to make them fit the page. Below is the CSS code for the main page:

I wanted to mimic a window application with my design. However, I encountered an issue where zooming in on the page would display a scroll bar on the main page. The parameters I set for the main page (the parent) are as follows: width: 100vw, height: 100vh

The challenge was figuring out how to scroll through the child components inside the main page rather than the main page itself. Here is the CSS part of my code:

The initial CSS code for the main page (parent). I utilized Material-ui for styling. 'root' is the className of the main page, while 'header', 'breadcrumb', and 'content' are classNames of the children components.

const useStyles = makeStyles({

root: {

width:"100vw",
height:"100vh",

},

header: {

height: "10%",
width: "100%",

},

breadcrumb: {

height: "10%",
width: "100%",

},

content: {

height: "80%",
width: "100%"

}, });

And the CSS code for the Content component, which consists of two components (Sidebar and content), is provided below:

const useStyles = makeStyles({

root: {

display: "flex",
width:"100%",
height:"100%",

},

sidebar: {

width: "20%",
height: "100%",
overflow: "auto",

},

content: {

width: "80%",
height: "100%",
overflow: "auto",

},

});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Optimal approach for handling onChange within useEffect

My child component is performing a fetch operation within a useEffect hook and then calling an onChange handler that is passed down from the parent. The issue is that the child component gets re-rendered three times, triggering the fetch operation three ti ...

The issue with updating state in React using dispatch within the same method is not working

Initially, I had a situation where the state was updating correctly with two separate methods (onClick). const sizesMeasureChoise = useSelector(getSizesMeasureChoise); const chooseMeasure = (measure) => { dispatch(setSizeMeasureChoise(measure)); ...

When using ReachJS, be mindful that whitespace text nodes should not be placed within `<tr>` elements. Double-check your code to ensure there is no unnecessary whitespace between tags on each line

I'm encountering the error message Warning: validateDOMNesting(...): Whitespace text nodes cannot appear as a child of . Make sure you don't have any extra whitespace between tags on each line of your source code. while attempting to include a ta ...

Moving the webpage into the realm of mobile and tablet devices

Over the next few weeks, I will be working on transitioning my website content to have both a mobile and tablet version. During this process, I have some questions: What is the best way to redirect users to the correct site based on their device/browse ...

Any tips for customizing the appearance of a {Switch} component from react-router-dom? I attempted to encase it in a <div> element, but it did

https://i.stack.imgur.com/4piCG.jpg https://i.stack.imgur.com/CyQH3.jpg My code attempts to modify the styling of the map component, but it seems to be influenced by the Switch component. How can I ensure that the screen fits within the 'root' ...

The appearance of Bootstrap React Nextjs doesn't quite match what's shown in the documentation

I am developing the frontend of my application using a combination of bootstrap, react, and nextjs. I attempted to implement the example provided by react-bootstrap at https://codesandbox.io/s/github/react-bootstrap/code-sandbox-examples/tree/master/basic. ...

What are the different ways to share data between components in React?

There are two components in my code, one named <Add /> and the other named <Modal>. The <Add /> component has a state for handling click events. Whenever the <Add /> component is clicked, the state is set to true. I need to utilize ...

What is the best library to utilize for uploading an Excel file in a React application?

As a beginner in JS and React, I have a simple question that I hope someone can help me with! I am trying to figure out how to upload an excel file using a form and then extract the data from the rows and columns. For example, I would like to calculate th ...

Is it advantageous to employ several wrapper-divs inside section elements when working with HTML5 and CSS?

Back in the day, I learned how to create a website by enclosing all content below the body tag within a div with the class "wrapper." This approach made sense as it allowed for easy vertical and horizontal alignment of the entire content. Just yesterday, ...

Utilizing Multer for MERN File Upload

For my project, I am working on creating a Pinterest-like platform where users can upload images. However, I am facing an issue with fetching files from the frontend to the backend using axios. Below is the code for the server: After testing various solut ...

Creating an animated background slide presentation

After creating a button group, I wanted the background of the previous or next button to move/slide to the selected one when the user clicks on it. I achieved this effect using pure CSS and simply adding or removing the 'active' class with jQuery ...

Creating a responsive 'media object' in Bootstrap 4: Tips and tricks

I have a media object that displays an image with text next to it, and it looks good on larger screens. However, when I switch to a smaller screen, the text overflows and the images appear in different sizes and positions. <div class="container&quo ...

React Color Input: The input format should follow the pattern of "#rrggbb", with rr, gg, and bb being two-digit hexadecimal values

The code is functioning correctly and as expected. The background color of the squares changes when each input is modified, and the squares update once the button is pressed. During development, there was a moment when the warning mentioned appeared brief ...

Trim the edge of a dynamic picture

Currently, I am facing a challenge with an image that requires the corner to be cut off. The image needs to be responsive in order to adjust its size according to the page dimensions. Since the image is managed by a CMS, the corner cut has to be done progr ...

Tips for Aligning an Image Just Above a Card in Mobile and Tablet Screens with Tailwind CSS

https://i.stack.imgur.com/tPXEQ.jpg https://i.stack.imgur.com/3XkJo.jpg Just a heads up, this code snippet performs well on desktop but may have some issues on mobile and tablet devices. If anyone in the StackOverflow Community can offer some assistance, ...

Encountering an Internal Server Error while running NextJs 13 in production environment, integrated with sanity and net

About I'm currently using Next.js and hosting my website on Netlify with CMS being Sanity. The blog page, which fetches content from Sanity, is encountering a 500 Internal Server Error when deployed on Netlify. However, it functions properly during l ...

Issue with Refresh Triggering Update, localStorage, useState, useEffect Combination

I want my app to execute the code inside the useEffect hook every 5 seconds, regardless of whether the page is refreshed or not. Currently, the code only runs when the page is refreshed and then remains inactive until the page is refreshed again. It seems ...

Pagination with React Material UI is a user-friendly and visually

Requirement Within the Material UI framework, I need to implement pagination functionality by clicking on the page numbers (e.g., 1, 2) to make an API call with a limit of 10 and an offset incrementing from 10 after the initial call. https://i.stack.imgur. ...

An element featuring a background color is vertically aligned in the middle of its parent container

Struggling to achieve a seemingly simple task, but coming up short on finding a solution. The goal is to have a background-color that aligns vertically in the middle of the first and last images in a stack of images. It may sound more complicated than it a ...

What is the best way to dynamically adjust the width of material-ui's drawer?

Is there a way to adjust the width of the material-ui's Drawer component based on window resize? The documentation mentions applying width using classes={{ paper: classes.root }}, but the issue is that classes.root cannot be changed dynamically as it ...