navbar change when scrolled with materialize css - html

I'm trying to replicate a navbar similar to this website. so there is a non-sticky navbar when user opens the website and after user scrolled down a little bit the non-sticky navbar gone and replaced by a sticky navbar. how can I achieve something like this with materialize css ? so far i've only made the non-sticky navbar part
<nav class="nav-extended">
<div class="nav-wrapper">
<img src="viva.png" alt="" id="logo">
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li>
<form>
<div class="input-field">
<input id="search" type="search" required>
<label class="label-icon" for="search"><i class="material-icons"></i></label>
<i class="material-icons">close</i>
</div>
</form>
</li>
<li>Register</li>
<li>|</li>
<li>Login</li>
</ul>
</div>
<hr>
<div class="nav-content">
<ul class="tabs tabs-transparent">
<li class="tab">Test 1</li>
<li class="tab">Test 2</li>
<li class="tab">Test 3</li>
</ul>
</div>
</nav>

Try this:
HTML
<div class="header">Header Example</div>
<div class="content">
<p>
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur.
</p>
</div>
CSS
body {
margin:0;
padding:0;
font-family: Arial, sans-serif;
}
header {
position: relative;
width: 100%;
height: 80px;
line-height: 80px;
background: #CCCCCC;
color: #333333;
padding-left: 25px;
}
header.fixed {
position:fixed;
top:-80px;
left: 0;
right: 0;
z-index:8888;
transition:0.3s top cubic-bezier(.3,.73,.3,.74);
}
body.on-scroll header.fixed {
top:0;
}
.content {
padding: 25px;
background: #fff;
line-height: 1.4;
color: #333;
min-height: 2700px; /* You can remove this,is just for demo purpose */
}
jquery:
(function($){
$(document).ready(function() {
var $header = $(".header"),
$clone = $header.before($header.clone().addClass("fixed"));
$(window).on("scroll", function() {
var fromTop = $(window).scrollTop();
$("body").toggleClass("on-scroll", (fromTop > 200));
});
});
})(jQuery);
Here's a jsfiddle example.

Related

How to have a Sticky Header and Footer with GRID that is not huge and stays in place?

Im trying to make a GRID layout where i have a Header that stays on top "sticky" while scrolling(if the page is very big) and that is not very tall, also i want this same thing with the footer, to be sticky and always visible and only a little bit tall, not huge and if the "main" is not big enough, stays in the bottom of the page...
i know how to do this with FlexBox, but im unable to achieve it with GRID, someone know how to do it?
Im trying to achieve this only with HTML and CSS
*{
margin: 0;
padding: 0;
}
body{
display: grid;
grid-template-columns: 1fr;
grid-template-areas:
"nav"
"main"
"foot" ;
grid-template-rows: auto, 1fr, auto;
height: 100vh;
}
.pageTop{
background-color: black;
color: white;
grid-area: nav;
position: sticky;
}
.mainIndex{
background-color: white;
color: blue;
grid-area: main;
}
.pageBottom{
background-color: black;
color: white;
grid-area: foot;
}
<body>
<header class="pageTop">
<h1><a href=index.html>The SOCIA Circle</a></h1>
<nav >
<ul class="ulNav">
<li>HOME</li>
</ul>
</nav>
</header>
<main class="mainIndex">
<h2>HOME</h2>
<img src="./imagenes/thesociacirclelogo.jpeg" alt="Photo showing a logo of The Socia Circle" width='300' class="photoIndex">
<p class="pIndex">Loret nisi, inventore ducimus distinctio nemo esse blanditiis animi hic officiis dicta exercitationem,
maxime tempora ipsam placeat, dolor ex eum? Provident dolorum ullam, nihil praesentium ad accusamus distinctio!
Deserunt blanditiis modi ipsa enim quibusdam quia facilis cum aut error, ullam sapiente vero qui? Aut tempore,
adipisci quibusdam, quis debitis consequatur labore vitae rerum quae placeat deleniti inventore asperiores!
Quia autem obcaecati animi ex quod quo, facere quisquam. Inventore facilis error ducimus aut ut qui nihil! A
sunt iste, libero perspiciatis magnam nesciunt necessitatibus corrupti repellat error, fuga aperiam!
Voluptas dolor at quod, et eveniet nihil odio adipisci repellendus! Cum incidunt consequuntur minus id beatae?
Cupiditate vel architecto aspernatur quas? Velit sapiente unde aut fugiat quas amet omnis veniam.
Autem qui iste soluta necessitatibus labore delectus eaque veritatis sequi? Minus reiciendis adipisci sit
soluta modi eos illum, architecto ab repellendus assumenda eum dolor quam quasi pariatur magnam labore atque.
Dignissimos maiores aliquam aspernatur. Id laudantium quam numquam accusantium illo. Ad illum exercitationem
fugiat nulla, eos cumque optio reiciendis ex sequi sed aliquid quaerat dolore pariatur dolores dicta maiores dolorum.</p>
</main>
<footer class="pageBottom">
<ul class="pFooter">
<li> The SOCIA Circle</li>
</ul>
<section class="sectionFooter">
<ul class="ulFooter">
<li><a href="https://www.instagram.com/sociacircle_ba" target="_blank" class="liFooter" >Instagram</a></li>
</ul>
</section>
</footer>
How about this?
.pageTop{
position: fixed;
width: 100%
}
.mainIndex{
margin-top: 80px;
}

Empty bar on the right side (Only on mobile or when browser is resized)

I've just started learning CSS, so I made was trying to make a website.
It looks fine on pc. But there's this unwanted space on the right side when I resize the browser or load the website on my phone.
I think the problem lies in my CSS's navbar where I used display type "flex". But nothing I do fixes the problem.
Here's 2 screenshots I took.
1
2
body{margin: 0em; padding: 0em;
font-family: Calibri;
color: white;
background-color: black;
height: 100%;
width: 100%;}
.backgroundimage
{height: 100%;
width: 100%;
position: absolute;
top: 0px;
bottom: 0px;
right: 0px;
left: 0px;
background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,1)),
url(https://rohitgejje.github.io/onepiecesample/images/onepiece.jpg);
z-index: -1;
background-size: cover;
}
/*--------------I think the problem lies here------------------------*/
.navbar {padding: 1em;
background: linear-gradient(rgba(0, 0, 0, 0.6)40%, rgba(0, 0, 0, 0));}
.navbar>nav>ul>img {margin-right: 1em;
margin-left: 1em;}
.navbar>nav>ul {display: flex;}
.navbar>nav>ul>li {display: block;
margin: auto;}
.link {text-decoration: none;
color: rgb(255, 255, 255);
font-size: 1.25em;
padding: 1em;}
/*---------------------------------------------------------------------*/
.hugelogo {text-align: center;}
.news {text-align: center;}
.news>ul {display: flex;}
.news>ul>li {display:block; margin: auto;}
.about>h1 {text-align: center;}
.about>p {margin: 2em;}
.membershome {text-align: center;}
.membershome>ul {display: flex;}
.membershome>ul>li {display: block;
margin: auto;}
.galleryhome {text-align: center;}
.galleryhome>img {margin: 0.5em;}
.historyhome {text-align: center;
margin-top: 3rem;}
/* javascript starts here*/
.link:hover {background: radial-gradient( rgba(0,0,0,0.5), rgba(0,0,0,0)75%);
border-radius: 10%;}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Straw Hat Pirates</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="backgroundimage"></div>
<header class="header">
<div class="navbar">
<nav>
<ul>
<img src="https://unsplash.it/100/40" alt="logo" class="logonav">
<li >Home</li>
<li >Gallery</li>
<li >History</li>
<li >Login</li>
</ul>
</nav>
</div>
</header>
<section>
<div class="hugelogo">
<img src="https://unsplash.it/400/225" alt="logo" class="bigimghome">
</div>
<div class="news">
<h3>News</h3>
<ul>
<li>update1</li>
<li>update2</li>
<li>update3</li>
<li>update4</li>
<li>update5</li>
<li>update6</li>
</ul>
</div>
<div class="about">
<h1>About</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing
elit. Ut dolor et excepturi quia temporibus vero nisi?
Qui iste beatae dolorum explicabo? Velit quia ipsa voluptates
ea nemo veritatis amet aperiam modi aliquid expedita assumenda
neque, vel nihil, incidunt nam nesciunt illo consequatur eum
possimus numquam fuga. Mollitia repellendus iure, soluta illum
sapiente perspiciatis architecto beatae accusamus ad ut dolor
at est delectus non dolores neque quasi, vel eligendi libero
porro aliquam corporis veniam similique? Laudantium nulla quae
architecto, facere cumque culpa excepturi placeat quia quidem
ipsum. Veniam deleniti autem voluptas molestias suscipit
reprehenderit possimus iure. Cupiditate a odit quidem. Nam
molestiae odio quos esse iure deleniti voluptatum magnam
rerum laudantium? Molestias ullam itaque, expedita
blanditiis quasi asperiores dolores numquam similique error,
laboriosam necessitatibus. Quos soluta officiis doloremque,
harum quibusdam voluptas. Quia quisquam nulla laboriosam
necessitatibus laudantium sunt recusandae corrupti tempore, nisi
assumenda, accusantium, culpa quas? Dignissimos numquam reiciendis possimus
facere.</p>
</div>
<div class="membershome">
<h2>Members</h2>
<ul>
<li class="memberhome">member1</li>
<li class="memberhome">member2</li>
<li class="memberhome">member3</li>
<li class="memberhome">member4</li>
<li class="memberhome">member5</li>
<li class="memberhome">member6</li>
</ul>
</div>
<div class="galleryhome">
<h2>Gallery</h2>
<img src="https://www.unsplash.it/100/100" alt="img1">
<img src="https://www.unsplash.it/100/100" alt="img2">
<img src="https://www.unsplash.it/100/100" alt="img3">
<img src="https://www.unsplash.it/100/100" alt="img4">
</div>
<div class="historyhome">
<h2>History</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing
elit. Suscipit cum perferendis dolorem magni laboriosam.
Iste cumque, reiciendis distinctio sequi quidem dolore hic
et repellendus deserunt ratione nisi velit provident?
Laudantium.</p>
</div>
</section>
<footer class="footer">
<div class="footer">
<nav>
<ul>
<li>IG</li>
<li>FB</li>
<li>SC</li>
<li>WA</li>
</ul>
</nav>
</div>
</footer>
</body>
</html>
Any help is appreciated. Thank you
3:Github link
So what's basically happening here is that your navbar is overflowing your body. While section takes only 100% width in body. So in this condition you have following option:
either add a scrollbar to navbar. (Quick fix)
add flex-wrap:wrap;.(navbar options will arrange themselves on second line, also a quick fix.)
Even expand your background with your navbar.(which I did in following code by setting body width:auto; which is 100% by default, now in mobile devices your website will look like just aa minimized version of pc site, Won't say its a good thing but if you want to make it work you have to work with media queries. which is to like write whole code)
Add a collapsing menu.(again media queries and code for creating collapsing navbar)
body{margin: 0em; padding: 0em;
font-family: Calibri;
color: white;
background-color: black;
height: 100%;
width: auto;}
.backgroundimage
{height: 100%;
width: 100%;
position: absolute;
top: 0px;
bottom: 0px;
right: 0px;
left: 0px;
background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,1)),
url(https://rohitgejje.github.io/onepiecesample/images/onepiece.jpg);
z-index: -1;
background-size: cover;
}
/*--------------I think the problem lies here------------------------*/
.navbar {padding: 1em;
background: linear-gradient(rgba(0, 0, 0, 0.6)40%, rgba(0, 0, 0, 0));}
.navbar>nav>ul>img {margin-right: 1em;
margin-left: 1em;}
.navbar>nav>ul {display: flex;}
.navbar>nav>ul>li {display: block;
margin: auto;}
.link {text-decoration: none;
color: rgb(255, 255, 255);
font-size: 1.25em;
padding: 1em;}
/*---------------------------------------------------------------------*/
.hugelogo {text-align: center;}
.news {text-align: center;}
.news>ul {display: flex;}
.news>ul>li {display:block; margin: auto;}
.about>h1 {text-align: center;}
.about>p {margin: 2em;}
.membershome {text-align: center;}
.membershome>ul {display: flex;}
.membershome>ul>li {display: block;
margin: auto;}
.galleryhome {text-align: center;}
.galleryhome>img {margin: 0.5em;}
.historyhome {text-align: center;
margin-top: 3rem;}
/* javascript starts here*/
.link:hover {background: radial-gradient( rgba(0,0,0,0.5), rgba(0,0,0,0)75%);
border-radius: 10%;}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Straw Hat Pirates</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="backgroundimage"></div>
<header class="header">
<div class="navbar">
<nav>
<ul>
<img src="https://unsplash.it/100/40" alt="logo" class="logonav">
<li >Home</li>
<li >Gallery</li>
<li >History</li>
<li >Login</li>
</ul>
</nav>
</div>
</header>
<section>
<div class="hugelogo">
<img src="https://unsplash.it/400/225" alt="logo" class="bigimghome">
</div>
<div class="news">
<h3>News</h3>
<ul>
<li>update1</li>
<li>update2</li>
<li>update3</li>
<li>update4</li>
<li>update5</li>
<li>update6</li>
</ul>
</div>
<div class="about">
<h1>About</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing
elit. Ut dolor et excepturi quia temporibus vero nisi?
Qui iste beatae dolorum explicabo? Velit quia ipsa voluptates
ea nemo veritatis amet aperiam modi aliquid expedita assumenda
neque, vel nihil, incidunt nam nesciunt illo consequatur eum
possimus numquam fuga. Mollitia repellendus iure, soluta illum
sapiente perspiciatis architecto beatae accusamus ad ut dolor
at est delectus non dolores neque quasi, vel eligendi libero
porro aliquam corporis veniam similique? Laudantium nulla quae
architecto, facere cumque culpa excepturi placeat quia quidem
ipsum. Veniam deleniti autem voluptas molestias suscipit
reprehenderit possimus iure. Cupiditate a odit quidem. Nam
molestiae odio quos esse iure deleniti voluptatum magnam
rerum laudantium? Molestias ullam itaque, expedita
blanditiis quasi asperiores dolores numquam similique error,
laboriosam necessitatibus. Quos soluta officiis doloremque,
harum quibusdam voluptas. Quia quisquam nulla laboriosam
necessitatibus laudantium sunt recusandae corrupti tempore, nisi
assumenda, accusantium, culpa quas? Dignissimos numquam reiciendis possimus
facere.</p>
</div>
<div class="membershome">
<h2>Members</h2>
<ul>
<li class="memberhome">member1</li>
<li class="memberhome">member2</li>
<li class="memberhome">member3</li>
<li class="memberhome">member4</li>
<li class="memberhome">member5</li>
<li class="memberhome">member6</li>
</ul>
</div>
<div class="galleryhome">
<h2>Gallery</h2>
<img src="https://www.unsplash.it/100/100" alt="img1">
<img src="https://www.unsplash.it/100/100" alt="img2">
<img src="https://www.unsplash.it/100/100" alt="img3">
<img src="https://www.unsplash.it/100/100" alt="img4">
</div>
<div class="historyhome">
<h2>History</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing
elit. Suscipit cum perferendis dolorem magni laboriosam.
Iste cumque, reiciendis distinctio sequi quidem dolore hic
et repellendus deserunt ratione nisi velit provident?
Laudantium.</p>
</div>
</section>
<footer class="footer">
<div class="footer">
<nav>
<ul>
<li>IG</li>
<li>FB</li>
<li>SC</li>
<li>WA</li>
</ul>
</nav>
</div>
</footer>
</body>
</html>

stick footer at the bottom in Reactjs

I'm working on a project in React and ran into a problem that has me stumped.
I want to add footer component but its not working properly.
so here is my code and i am not able to figure out how to keep footer at bottom of my page when ever i scroll down.
if any one have some solution it will be really great if you help me
when i load my page footer componet look like this at bottom of my page
but when i scroll up then it look like this
i am wirting this code in different page (footer.jsx) with footer.module.css and calling in my app.js
Footer.jsx
import React from "react";
import footerStyles from "../styles/Footer.module.css";
import { FaTwitter, FaFacebook, FaInstagram } from "react-icons/fa";
function Footer() {
return (
<div id={footerStyles.copyright}>
<p>
© Team NexT LeVeL. All rights reserved. | Design by Team NexT
LeVeL
</p>
<ul className={footerStyles.contact}>
<li>
<a href="/#">
<FaTwitter size="2em" color="cyan" />
</a>
</li>
<li>
<a href="/#">
<FaFacebook size="2em" color="#00acee" />
</a>
</li>
<li>
<a href="/#">
<FaInstagram size="2em" className={footerStyles.insta} />
</a>
</li>
</ul>
</div>
);
}
export default Footer;
my footer.module.css look like this
#copyright {
margin: 0;
width: 100%;
border-top: 20px solid rgba(255, 255, 255, 0.08);
text-align: center;
background: #333333;
position: absolute;
left: 0;
bottom: 0;
right: 0;
bottom: 0;
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
flex: 0 0 25%;
}
#copyright p {
display: inline;
letter-spacing: 1px;
font-size: 16px;
color: white;
}
#copyright a {
text-decoration: none;
color: white;
}
/*footer icon*/
ul.contact {
list-style: none;
}
ul.contact li {
display: inline;
font-size: 1em;
padding: 10px;
}
ul.contact li span {
margin: 20px;
}
ul.contact li a {
color: white;
}
ul.contact li a:before {
display: inline;
background: #4c93b9;
line-height: 40px;
text-align: center;
color: rgba(255, 255, 255, 1);
}
.insta {
border-radius: 10px;
background: radial-gradient(
circle at 30% 107%,
#fdf497 0%,
#fdf497 5%,
#fd5949 45%,
#d6249f 60%,
#285aeb 90%
);
}
Try using
position: fixed;
instead of
position: absolute;
Also, I would suggest floating the element to make sure that the rest of the page isn't moving out of it's way incorrectly:
float: left;
And then add a padding to the bottom of your body tag with a height taller than your footer, to ensure you don't totally cover anything up
body {
padding-bottom: 100px;
}
Follow this structure.
const App = () => (
<div style={{paddingBottom: 50}}>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Voluptas, molestiae. Magni quibusdam doloremque optio rerum ex assumenda mollitia suscipit praesentium, exercitationem ea perspiciatis aut, voluptatum necessitatibus numquam totam. Commodi distinctio nisi non? Voluptas exercitationem nemo aut rem sint? Recusandae nam quisquam maiores sapiente ratione deleniti, corrupti impedit laboriosam voluptatibus repudiandae qui cumque voluptatem labore necessitatibus sed quidem nemo cum, vitae consequatur rem corporis quibusdam non voluptates quia. Amet ipsum ex, dolore quaerat omnis animi placeat totam alias suscipit eveniet voluptate doloremque nisi repellendus sit incidunt, voluptates ratione ea autem esse maiores, qui quasi? Possimus, velit quibusdam! Natus accusantium voluptatem asperiores.Lorem ipsum dolor, sit amet consectetur adipisicing elit. Voluptas, molestiae. Magni quibusdam doloremque optio rerum ex assumenda mollitia suscipit praesentium, exercitationem ea perspiciatis aut, voluptatum necessitatibus numquam totam. Commodi distinctio nisi non? Voluptas exercitationem nemo aut rem sint? Recusandae nam quisquam maiores sapiente ratione deleniti, corrupti impedit laboriosam voluptatibus repudiandae qui cumque voluptatem labore necessitatibus sed quidem nemo cum, vitae consequatur rem corporis quibusdam non voluptates quia. Amet ipsum ex, dolore quaerat omnis animi placeat totam alias suscipit eveniet voluptate doloremque nisi repellendus sit incidunt, voluptates ratione ea autem esse maiores, qui quasi? Possimus, velit quibusdam! Natus accusantium voluptatem asperiores.
</p>
<Footer/>
</div>
)
function Footer() {
return (
<div style={{
display:"flex",
position:"fixed",
width:"100%",
height: 50,
backgroundColor: "grey",
bottom: 0,
}}>
<p>
© Team NexT LeVeL. All rights reserved. | Design by Team NexTLeVeL
</p>
<ul style={{display:"flex"}}>
<li>
<a href="/#">
Twitter
</a>
</li>
<li>
<a href="/#">
Facebook
</a>
</li>
<li>
<a href="/#">
Instagram
</a>
</li>
</ul>
</div>
);
}
ReactDOM.render(<App />, document.getElementById("react"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.8.4/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.4/umd/react-dom.production.min.js"></script>
<div id="react"></div>

How can I make my nav sticky to the top of the page?

Tried to use some different methods but nothing really happened. This is my code, how can I make it sticky to the top of the page when scrolling down?
When I tried it the nav was behind the photo's and the text on the page. Anyone who could help me out?
<!-- Header start -->
<header>
<div class="menu-area" id="">
<div class="container">
<div class="row">
<div class="col-md-3">
<div class="logo">
<!--== change the logo name ==-->
<a href="index.html">
<h3><span>CHRISTIAAN</span>DESMET</h3>
</a>
</div>
<!-- Responsive Menu Start -->
<div class="responsive-menu"></div>
<!-- Responsive Menu End -->
</div>
<div class="col-md-9 col-sm-12">
<div class="mainmenu">
<nav>
<ul id="navigation">
<li class="current-page-item">home
</li>
<li>
<a href="#overmij">
over mij
</a>
</li>
<li>
producten
</li>
<li>contact</li>
</ul>
</nav>
</div>
</div>
</div>
</div>
</div>
</header>
<!-- Header End -->
HTML:
<div id="navbar">
<!-- navbar content Here -->
</div>
CSS:
#navbar {
overflow: hidden;
background-color: #333;
}
/* when navbar reaches top this should be added using JS*/
.sticky {
position: fixed;
top: 0;
width: 100%;
}
/* Add some top padding to the page content to prevent sudden quick movement (as the navigation bar gets a new position at the top of the page (position:fixed and top:0) */
.sticky + .content {
padding-top: 60px;
}
JS:
// When the user scrolls the page, execute myFunction
window.onscroll = function() {myFunction()};
// Get the navbar
var navbar = document.getElementById("navbar");
// Get the offset position of the navbar
var sticky = navbar.offsetTop;
// Add the sticky class to the navbar when you reach its scroll position. Remove "sticky" when you leave the scroll position
function myFunction() {
if (window.pageYOffset >= sticky) {
navbar.classList.add("sticky")
} else {
navbar.classList.remove("sticky");
}
}
Just add class name and change as per your requirement
.sticky {
position: -webkit-sticky;
position: sticky;
top: 0;
}
It seems you are also using Bootstrap, if so; what you want is really simple; you just have to add the sticky-top class to the navbar and you're good to go, see here:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<p>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Unde illum voluptatibus, laborum porro quibusdam officiis cum repudiandae iusto neque, consequatur consectetur error beatae maiores eaque ratione qui temporibus iste quisquam modi minima doloremque
iure. Cumque et labore incidunt alias enim magnam cum nam id ullam, modi nisi eos illo eaque amet hic eum ea natus consequatur necessitatibus! Asperiores, quaerat perspiciatis quibusdam laudantium sunt illo libero ex aspernatur dolores explicabo rem
architecto eos ipsa temporibus repudiandae itaque fugiat tempore ducimus ad eligendi reiciendis commodi. Molestiae ea necessitatibus in dolorum inventore vero et rerum dolore similique, dolores porro adipisci facilis, blanditiis obcaecati cumque, quisquam
voluptatibus nisi magni doloribus rem voluptatem explicabo quis accusantium quibusdam! At quo laudantium ad id eaque ex voluptas illum? Id, beatae. Ducimus, quam assumenda? Dignissimos ad iusto accusamus obcaecati, laudantium blanditiis nam non in repellat
iste repellendus suscipit magni est sapiente vero dolorem deserunt velit veritatis eius inventore?
</p>
<nav class="navbar navbar-expand sticky-top navbar-dark bg-primary">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
<p>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Unde illum voluptatibus, laborum porro quibusdam officiis cum repudiandae iusto neque, consequatur consectetur error beatae maiores eaque ratione qui temporibus iste quisquam modi minima doloremque
iure. Cumque et labore incidunt alias enim magnam cum nam id ullam, modi nisi eos illo eaque amet hic eum ea natus consequatur necessitatibus! Asperiores, quaerat perspiciatis quibusdam laudantium sunt illo libero ex aspernatur dolores explicabo rem
architecto eos ipsa temporibus repudiandae itaque fugiat tempore ducimus ad eligendi reiciendis commodi. Molestiae ea necessitatibus in dolorum inventore vero et rerum dolore similique, dolores porro adipisci facilis, blanditiis obcaecati cumque, quisquam
voluptatibus nisi magni doloribus rem voluptatem explicabo quis accusantium quibusdam! At quo laudantium ad id eaque ex voluptas illum? Id, beatae. Ducimus, quam assumenda? Dignissimos ad iusto accusamus obcaecati, laudantium blanditiis nam non in repellat
iste repellendus suscipit magni est sapiente vero dolorem deserunt velit veritatis eius inventore?
</p>
<p>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Unde illum voluptatibus, laborum porro quibusdam officiis cum repudiandae iusto neque, consequatur consectetur error beatae maiores eaque ratione qui temporibus iste quisquam modi minima doloremque
iure. Cumque et labore incidunt alias enim magnam cum nam id ullam, modi nisi eos illo eaque amet hic eum ea natus consequatur necessitatibus! Asperiores, quaerat perspiciatis quibusdam laudantium sunt illo libero ex aspernatur dolores explicabo rem
architecto eos ipsa temporibus repudiandae itaque fugiat tempore ducimus ad eligendi reiciendis commodi. Molestiae ea necessitatibus in dolorum inventore vero et rerum dolore similique, dolores porro adipisci facilis, blanditiis obcaecati cumque, quisquam
voluptatibus nisi magni doloribus rem voluptatem explicabo quis accusantium quibusdam! At quo laudantium ad id eaque ex voluptas illum? Id, beatae. Ducimus, quam assumenda? Dignissimos ad iusto accusamus obcaecati, laudantium blanditiis nam non in repellat
iste repellendus suscipit magni est sapiente vero dolorem deserunt velit veritatis eius inventore?
</p>

Why is the inner div trying to clear other divs?

*NEW UPDATED JSFiddle http://jsfiddle.net/qKP2v/8/*
I have a very simple layout of two sidebars floated left and right respectively. In the middle is a #maincontent div that has a #content div within it. The reason for this is so that the main content on the page can stretch to fill the size of the browser resolution.
The problem I have is when I want to insert divs (#rectanglebox1, #rectanglebox2, #rectanglebox3) that clears left and right floats within my #content div. But the #rectanglebox divs are trying to clear the sidebars which doesn't make any sense to me. The #rectanglebox divs are within the #content area which has no float applied to it. So why is the #rectanglebox div being pushed below the sidebars?
Here is my HTML:
<div id="wrapper">
<div id="maincontent">
<div id="aside-left">
<ul>
<li>Link1</li>
<li>Link2</li>
<li>Link3</li>
</ul>
</div>
<div id="aside-right">
<ul>
<li>Link1</li>
<li>Link2</li>
<li>Link3</li>
</ul>
</div>
<div id="content">
<div id="ataglance">
<div id="rectanglebox1"><p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p></div>
<div id="rectanglebox2"><p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p></div>
<div id="rectanglebox3"><p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p></div>
</div>
</div>
<div style="clear:both;"></div>
</div>
</div>
And here is my CSS:
#wrapper {
width:100%;
margin: 0 auto;
background-color: #FFF;
min-height:200px;
border: 1px solid #F0F;
}
#aside-left {
height: 400px; /* guess */
float:left;
width:100px;
top: 0;
left: 0;
border: 1px solid #9C0;
}
#maincontent {
border: 1px solid #9C0;
width:100%;
}
#maincontent #content{
margin:0 130px;
border: 1px solid red;
}
#aside-right {
height: 400px; /* guess */
float:right;
width:100px;
top: 0;
right: 0;
text-align: right;
border: 1px solid #9C0;
}
#ataglance {
border: 2px solid black;
}
#rectanglebox1 {
float:left;
margin-top:5px;
border: 1px solid orange;
width:200px;
}
#rectanglebox2 {
float:left;
margin-top:5px;
border: 1px solid orange;
width:250px;
}
#rectanglebox3 {
float:left;
margin-top:5px;
border: 1px solid orange;
width:300px;
}
try this code it's working for me !
<div id="wrapper">
<div id="maincontent">
<div id="aside-left">
<ul>
<li>Link1</li>
<li>Link2</li>
<li>Link3</li>
</ul>
</div>
<div id="aside-right">
<ul>
<li>Link1</li>
<li>Link2</li>
<li>Link3</li>
</ul>
</div>
<div id="content">
<div id="rectanglebox"><p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur</p></div>
<div style="clear:both;"></div>
</div>
<!-- <div style="clear:both;"></div> no need for this -->
</div>
</div>
and modify your css :
#rectanglebox {
margin-top:30px;
border: 1px solid orange;
float:left;
}