VladKrav VladKrav - 7 months ago 13
HTML Question

Page gets cut off on the right side after javascript runs

When I scroll down the right side of the page gets cut off and glitches. Whats supposed to happen is when you scroll down the page scrolls over the header until it reaches the navbar and then the navbar sticks and scrolls down with the rest of the page. I feel like this is a simple mistake that I am overlooking. Any help is appreciated :)



<script>
var mn = $(".main-nav");
mns = "main-nav-scrolled";
hdr = $('header').height();

$(window).scroll(function() {
if( $(this).scrollTop() > hdr ) {
mn.addClass(mns);
} else {
mn.removeClass(mns);
}
});
</script>

* {
box-sizing: border-box;
}
body {
margin: 0;
padding-top: 550px;
margin-bottom:-10px;
}
header {
height: 605px;
padding-top: 50px;

}
.main-nav,
.main {
position: relative;
}
.main-nav {
background: #fff;
height: 70px;
z-index: 150;
margin-bottom: -60px;
box-shadow: 0 4px 6px rgba(0,0,0,.4);
overflow: hidden;
width:100%;
padding-top:0px;
}
header,
.main-nav-scrolled {
position: fixed;
width: 100%;
top: 0;
list-style-type: none;
margin-top: 0px;
margin: 15;
padding: 0;
overflow: hidden;
}
.main-nav-scrolled {
list-style-type: none;
margin-top: 0px;
margin: 15;
padding: 0;
overflow: hidden;
background-color: #333;
}
.main {
background-image: url("img/tiles2.png");
background-attachment:fixed;
padding: 120px 50px 55px;
column-count: 2;
column-gap: 40px;
}

/* ------------------------------------*/
.main-nav ul {
width: 100%;
list-style-type: none;
margin-top: 0px;
margin: 15;
padding: 0;
overflow: hidden;
background-color: #333;


}

.main-nav li {
float: left;
}

.main-nav li:last-child {
border-right: none;
}

.main-nav li a {
display: block;
color: white;
text-align: center;
padding: 26px 29px;
text-decoration: none;
}

.main-nav li a:hover:not(.active2) {
background-color: #111;
}

.main-nav .active2 {
background-color: #4CAF50;
}



.para{
position: relative;
height:380px;
display: inline-block;
margin-left: 20px;
margin-right: 20px;
margin-top:30px;
background-color: #FFFFFF;
padding: 20px;
font-size:20px;
font-family:verdana;
line-height:2;
overflow:auto;
border-radius: 20px;
}

.circles{
width:100%;

}
.bigText{

}

/*----------------------------------------------------*/

.position{
font-family: 'Lobster', cursive;
font-size:24px;
word-spacing:10px;
}
.name{
font-size:24px;
}

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Officers</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!--<link href="http://fonts.googleapis.com/css?family=Lato:100,300,400,700,900" rel="stylesheet" type="text/css"-->
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />>
<link href="css/owl.carousel2.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/magnific-popup.css">
<!--<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">-->
<script type="text/javascript" src="js/jquery.min.js"></script>
<link rel="stylesheet" href="css/paragraph.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<body>

<ul>
<li><a href="Index.html">Home</a></li>
<li style="float:right"><a href="Competitions2.html">Competitions</a></li>
<li style="float:right"><a href="about2.html">About</a></li>
</ul>

<header>
<img src="img/officers.png" alt="header" style="width:100%;">
</header>

<div class="main-nav">
<ul>
<li><a href="Index.html">Home</a></li>
<li style="float:right"><a href="Competitions2.html">Competitions</a></li>
<li style="float:right"><a href="about2.html">About</a></li>
</ul>
</div>

<div class="main">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident.
</p></div>
</body>
</html>




Answer

Your JavaScript looks fine. I did notice a few errors in your document head though. Clean that up so that it looks like this.

<head>
<meta charset="utf-8">
<title>Officers</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href="css/style.css" rel="stylesheet" type="text/css" media="all">
<link href="css/owl.carousel2.css" rel="stylesheet" type="text/css">
<link href="css/magnific-popup.css" rel="stylesheet" type="text/css">
<link href="css/paragraph.css" rel="stylesheet" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>

Your CSS has some errors as well. there are a number of margins that are missing the px units. eg, margin:15. You are applying list styles on divs. eg, list-style-type: none; on header, .main-nav-scrolled, that's not required. Also update your column css so that it supports all browsers. eg;

-webkit-column-count: 3; /* Chrome, Safari, Opera */
-moz-column-count: 3; /* Firefox */
column-count: 3;

But the real reason why the width of the .main <div> cuts off on the right, or just plain gets narrower is because of the floats you have used on the top <ul> list items. You need to clear these floats. What's happening is that when you scroll and the header and main-nav become fixed the next element that follows the top <ul> is the .main <div>. If you add clear:both; to .main that will fix your problem.

http://codepen.io/partypete25/pen/RaYVOL

Comments