Reputation: 107
I am building a React.js website app for a university project which uses Reactstrap as well as my custom CSS. I have just noticed that I have horizontal scrolling but I cannot figure out where it is coming from.
You can see the extra space on the image, it seems to be something to do with the navbar but I just have no idea why and have played around with the CSS a lot. I must be completely missing something?
Code for the Navbar.js component:
import Navbar from 'react-bootstrap/Navbar';
import Nav from 'react-bootstrap/Nav';
import Button from 'react-bootstrap/Button';
import {
Link
} from 'react-router-dom';
class NavBar extends React.Component {
render() {
return (
<Navbar expand="md" className="custom-nav-bg fixed-top">
<Navbar.Brand expand="lg" href="#home">
<Link to="/home"><img className="custom-nav-logo"
src="logohero.png"
alt="StatHero Logo"
width="105px"
height="50px"
/></Link>
</Navbar.Brand>
<Nav className="collapse navbar-collapse mr-auto justify-content-end">
<Nav.Link className="custom-nav-text" href="#about">
<Link to="/about">ABOUT</Link>
</Nav.Link>
<Nav.Link className="custom-nav-text" href="#stats">
<Link to="/stats">STATS</Link>
</Nav.Link>
<Nav.Link className="custom-nav-text" href="#faqs">
<Link to="/faq">FAQS</Link>
</Nav.Link>
<Nav.Link className="custom-nav-text" href="#contact">
<Link to="/contact">CONTACT</Link>
</Nav.Link>
<Nav.Link className="custom-nav-text" href="#signup">
<Button className="custom-nav-button">SIGN UP</Button>
</Nav.Link>
<Nav.Link className="custom-nav-text" href="#login">
LOGIN
</Nav.Link>
</Nav>
</Navbar>
)
}
}
export default NavBar;
Code for my custom.css:
background-color: #132A42;
border-radius: 0px;
padding-left: 60px;
padding-right: 50px;
}
.custom-nav-logo {
height: 100%;
}
a:focus, a:hover, a:active {
color: white ! important;
font-family: 'Assistant', sans-serif ! important;
font-weight: 650 ! important;
text-decoration: none;
}
a.custom-nav-text:hover {
color: white ! important;
font-family: 'Assistant', sans-serif ! important;
font-weight: 700 ! important;
}
.custom-nav-text {
color: white ! important;
font-family: 'Assistant', sans-serif;
font-weight: 600;
padding-left:20px ! important;
padding-right:20px ! important;
padding-top:10px ! important;
padding-bottom:10px ! important;
font-size: 20px;
}
.custom-usp-1 {
background-color: #F6F7F8;
}
.custom-usp-2 {
background-color: white;
}
.custom-nav-button {
border-radius: 20px;
border-color: #00DF8D;
background-color: #00DF8D;
font-size: 20px;
font-weight: 600;
padding-left: 15px;
}
.custom-jumbo-button {
border-radius: 35px;
border-color: #00DF8D;
background-color: #00DF8D;
font-size: 40px;
font-weight: 600;
padding-left: 50px;
padding-right: 50px;
text-align: center;
margin-top: 10px;
}
.CTA {
background-color: #C42B32;
}
.custom-jumbo {
padding-bottom: 150px ! important;
padding-top: 210px ! important;
background-color: #132A42;
margin-bottom: 0px;
padding-left: 75px;
}
h1 {
color: white ! important;
font-family: 'Assistant', sans-serif;
font-size: 50px ! important;
font-weight: 700;
}
h2 {
color: white ! important;
font-family: 'Assistant', sans-serif;
font-size: 25px;
text-align: center;
padding-top: 10px;
padding-bottom: 8px;
font-weight: 600;
letter-spacing: 3px;
}
p {
color: white ! important;
font-family: 'Assistant', sans-serif;
font-size: 30px ! important;
}
h3 {
color: black ! important;
font-family: 'Assistant', sans-serif;
font-size: 30px;
text-align: center;
padding-top: 40px;
padding-bottom: 5px;
font-weight: 600;
}
h4 {
color: #C42B32 ! important;
font-family: 'Assistant', sans-serif;
font-size: 40px;
text-align: center;
padding-bottom: 15px;
font-weight: 600;
}
.USPp {
color: black ! important;
font-family: 'Assistant', sans-serif;
font-size: 20px ! important;
text-align: center;
padding-right: 60px ! important;
padding-left: 60px ! important;
font-weight: 500;
padding-bottom: 50px;
}
.customCard {
font-family: 'Assistant', sans-serif;
font-weight: 550;
color: #C42B32 ! important;
text-align: center;
font-size: 20px ! important;
}
.cardContent {
padding-left: 30px;
padding-right: 30px;
padding-top: 30px;
padding-bottom: 20px;
border: 0px solid rgba(0,0,0,.125) ! important;
}
.JumboImg {
background-color: #132A42;
height: 500px;
}
.customFooter {
background-color: #132A42;
height: 200px;
}
a {
color: white;
}
I can provide the code for the other components on the page if necessary.
Upvotes: 2
Views: 795
Reputation: 107
SOLVED
It was an issue with one of the other components.
I used dev tools to manually go through and delete elements to find out which one caused the horizontal scroll. I then edited the CSS for that component by adding
max-width: 100%;
This was a very helpful tutorial on how to do this: https://css-tricks.com/findingfixing-unintended-body-overflow/
Upvotes: 0
Reputation: 397
I think the body has some padding or margin...
add this class... I hope it will work:
body {
padding: 0;
margin: 0;
}
Upvotes: 1