Reputation: 97
I am noticing that my react application has an unwanted horizontal scroll. I see that if I comment out the <About/>
component then the scroll disappears. Not sure as to why it is getting added. It goes away if I add overflow-x: hidden
to App.css
but it doesnt seem like the right solution.
Also, I se that <About/>
= BLUE component is coming on the RED part. I am not able to understand why it is happening.
Appreciate any help.
These are the files and theScreenshot:
App.js
import React from "react";
import "./App.css";
import "bootstrap/dist/css/bootstrap.min.css";
import Landing from "./Components/Landing";
import About from "./Components/About";
function App() {
return (
<div className="App">
<Landing />
<About />
</div>
);
}
export default App;
App.css
.App {
height: 100vh;
width: 100vw;
max-width: 900px;
padding: 1rem;
background-color: lightpink;
}
Landing.js
import React from "react";
import "./Landing.css";
function Landing() {
return (
<div className="LandingContainer"></div>
}
export default Landing;
Landing.css
.LandingContainer {
height: 100%;
width: 100%;
background-color: lightgreen;
}
About.js
import React from "react";
import "./About.css";
function About() {
return (
<div className="MainAboutContainer"></div>
}
export default About;
About.css
.MainAboutContainer {
background-color: lightblue;
width: 100%;
height: 100%;
text-align: center;
}
Upvotes: 5
Views: 18732
Reputation: 51
Add this to your App.css
body {
overflow-y: hidden; /* Hide vertical scrollbar */
overflow-x: hidden; /* Hide horizontal scrollbar */
}
Upvotes: 3
Reputation: 20669
Do you have any other css enabled?
If not, try adding following in your App.css
:
*, *::before, *::after {
box-sizing: inherit;
}
html {
/* this makes sure the padding and the border is included in the box sizing */
box-sizing: border-box;
overflow-y: hidden;
}
html body {
padding: 0;
margin: 0;
overflow-y: inherit;
}
Additionally, you shouldn't add height: 100%
to both of your Landing
and About
element, it will double your app's height.
Try this, it'll remove the horizontal scroll and weird padding problem:
*, *::before, *::after {
box-sizing: inherit;
}
html {
/* this makes sure the padding and the border is included in the box sizing */
box-sizing: border-box;
overflow-y: hidden;
}
html body {
padding: 0;
margin: 0;
overflow-y: inherit;
}
.App {
height: 100vh;
width: 100vw;
max-width: 900px;
padding: 1rem;
background-color: lightpink;
}
.LandingContainer {
width: 100%;
height: 100%;
background-color: lightgreen;
}
.MainAboutContainer {
width: 100%;
height: 100%;
background-color: lightblue;
text-align: center;
}
Upvotes: 7