Sticky Navigation
How do I make an sticky navigation?
While the header and the content scroll, the nav element in between will scroll to the top of the window, but no further.. What is a sticky navigation? How do you make a sticky navigation? This script and codes were developed by Tom Hermans on 09 December 2022, Friday.
Sticky Navigation - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Sticky Navigation</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <html> <body> <div class="wrapper"> <div class="adzone-top"> <img src="http://placehold.it/728x90" alt="" /> </div> <header id="unstickyheader"> <h1>the Header and the content will scroll</h1> <h2>... but the nav won't</h2> </header> <nav id="stickyheader"> <ul> <li>Sticky Nav Item 1</li> <li>Sticky Nav Item 2</li> <li>Sticky Nav Item 3</li> <li>Sticky Nav Item 4</li> <li>Sticky Nav Item 5</li> </ul> </nav> <div class="content"> <h2>Text is "Getting Responsive" by Jonathan Snook</h2> <p>Copied from his e-mailing</p> <p>Spring is in the air! And what doesn’t put a spring in your step better than a little link love.</p>
<p>Responsive Modules</p>
<p>As people look to apply a modular approach to their CSS, they (as I have) question how to manage the conditional styling of a module in a particular state: namely, with media queries. The problem is that media queries give you information about the device or window width (with regards to fluid responsive designs) but you’re actually more concerned about what happens when this particular module hits a particular width.</p> <div class="box"> <div class="label"> <h3>Follow up meetings</h3> <p>25jan-2feb</p> </div> </div>
<p>If you try to solve the problem with CSS, you end up creating media query breakpoints where the module breaks within the overall design. That works as long as the design doesn’t change. It would be better if we could provide some conditionals around just the module, instead of trying to make it conditional to the entire layout.</p>
<p>Andrew Hathaway talks a bit about his approach to responsive web design using OOCSS. In the article, he recommends adding classes for each context. For example, adding a ‘left” class for floated containers on larger screens and adding a ‘stacked’ class for removing the float on a smaller screen. I don’t like this approach very much as you end up adding a number of context descriptors on any given element and you’re left referencing the source CSS to understand what should happen in different contexts.</p>
<p>Ian Storm Taylor thinks that Media Queries are a Hack and that we should be able to specify conditions on a specific container. Of course, infinite loops can rear their ugly heads here. For example, if outer div is 300px. But then outer div is >300px, which should resize the inner div back to what it was before. That’s not very good.</p>
<p>The other solution is to use JavaScript. Andy Hume has a post on Responsive Containers that also includes a script to accomplish a similar concept to being able to set a media query on a particular element.</p>
<p>Responsive Deliverables</p>
<p>On the subject of responsive, Dave Rupert had a recent post on dealing with deliverables on a responsive project. It has the best footnote ever! (But I might be biased.) The idea of putting together a system of components is a sound one. An organized system has a number of benefits including code reuse, code reduction, and design management. As Dave puts it, it’s like tiny Bootstraps for every client. As a project matures, each new module that you build becomes an opportunity to ask if it is necessary. Is it necessary to add more code? Is it necessary to add another design component that users have to learn?</p>
<p>Refactoring Bootstrap</p>
<p>Pamela Fox talks about her lessons learned in maintainable CSS that came from porting a project over from one version of Bootstrap to another. Pamela will be speaking at CSSConf next month on this very topic. (There are still tickets left!)</p>
<p>Thanks as always for listening. Until next time!</p>
<p>Jonathan Snook.</p> </div> </div>
</body>
</html> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Sticky Navigation - Script Codes CSS Codes
* { margin: 0; padding: 0;
}
html, body { font-family: sans-serif; margin: 0; padding: 0;
}
#unstickyheader, .content { width: 960px; max-width: 100%; background: #f1e9ff; height: 100px; padding-top: 100px;
}
#unstickyheader { background: #9675cd; color: white;
}
#stickyheader { width: 100%; background: red; z-index: 101;
}
#stickyheader ul { list-style: none; width: 960px; margin: 0 auto; padding: .75em 0;
}
#stickyheader ul li { display: inline-block; font-style: 800; font-family: arial; color: white; padding-right: 1em;
}
.box { background: blue; width: 150px; padding: 1em; height: 600px; position: relative;
}
.label { background: green; width: 75%; position: absolute; top: 0;
}
.adzone-top { background: #00f; border-bottom: 1px dashed #5d4e32; height: 100px; position: fixed; width: 100%;
}
Sticky Navigation - Script Codes JS Codes
$(function(){ // Check the initial Position of the Sticky Header var stickyElem = document.getElementById('stickyheader'); var stickyHeaderTop = $(stickyElem).offset().top - 100; $(window).scroll(function(){ if( $(window).scrollTop() > stickyHeaderTop ) { $(stickyElem).css({position: 'fixed', top: '100px'}); } else { $(stickyElem).css({position: 'static', top: '100px'}); } var boxpos = $('.box').position(); console.log(boxpos); }); });
Developer | Tom Hermans |
Username | tomhermans |
Uploaded | December 09, 2022 |
Rating | 3 |
Size | 4,529 Kb |
Views | 10,120 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Styled selectbox | 1,901 Kb |
Simple circle cutout css | 1,577 Kb |
CKEditor angular test | 15,138 Kb |
StickyNav | 4,306 Kb |
Media object module | 3,344 Kb |
Simple color ribbon | 1,788 Kb |
Accessibility wai-aria test | 8,599 Kb |
Imagemap pure css trial | 2,852 Kb |
CSS Kwicks | 2,202 Kb |
CSS3 Shapes reference | 2,574 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
IE flex collapse bug fix | Rowno | 2,678 Kb |
A Pen by Malith Hettiarachchi | MalZiiirA | 5,531 Kb |
Arrow Navigation | Hinducows | 1,973 Kb |
Fullscreen audio play button | 72 | 2,148 Kb |
Angular-HAML | Cwacht | 2,022 Kb |
Use the Twitchtv JSON API | Roksanaop | 3,561 Kb |
Mobile first social buttons with no iframe | Alistairtweedie | 3,158 Kb |
A Pen by Dalton Liu | Liudalton | 12,437 Kb |
CSS Flip Animation | Bbodine1 | 2,525 Kb |
Preloader | Rikki_Sixx | 2,815 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!