Computer >> कंप्यूटर >  >> प्रोग्रामिंग >> CSS

CSS के साथ ऑन स्क्रॉल फिक्स्ड नेविगेशन बार कैसे बनाएं?

<घंटा/>

CSS स्थिति विशेषता निर्दिष्ट करके, हम CSS का उपयोग करके एक निश्चित नेविगेशन बार बना सकते हैं।

CSS में पोजिशन प्रॉपर्टी का सिंटैक्स इस प्रकार है -

Selector {
   position: /*value*/;
}

निम्नलिखित सीएसएस स्थिति संपत्ति का एक उदाहरण है।

उदाहरण

<!DOCTYPE html>
<html>
<head>
<style>
#navigation-bar {
   overflow: hidden;
   box-shadow: inset 0 0 20px green;
}
a {
   float: left;
   display: block;
   margin-left: 2%;
   padding: 2% 4%;
   text-align: center;
   color: black;
   text-decoration: none;
   font-size: 1.2em;
   border: 0.5px ridge red;
}
a:hover {
   box-shadow: inset 0 0 14px red;
   font-size: 1.6em;
}
.content {
   background-color: coral;
   padding: 16px;
}
.sticky {
   position: fixed;
   top: 0;
   width: 100%;
}
.sticky + .content {
   padding-top: 80px;
}
</style>
</head>
<body>
<div class="content"></div>
<div id="navigation-bar">
<a class="active" href="#">logo</a>
<a href="#">SignUp</a>
<a href="#">SignIn</a>
<a href="#">More</a>
</div>
<div class="content">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum faucibus ante quis odio rhoncus, sit amet porta nunc venenatis. Vivamus eu ex et risus vehicula semper eu eu elit. Aliquam tempor rutrum neque sit amet aliquam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Cras non eros ex. Suspendisse placerat tincidunt tortor a semper. Etiam molestie justo ac sapien auctor maximus. Etiam ut ante sollicitudin, tempor mauris nec, malesuada purus. Nunc malesuada sem sed fermentum eleifend. Cras ultrices velit eu blandit lobortis.
</p>
<img src="https://images.unsplash.com/photo-1612305876291-
c369fea489b3?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=800&ixlib=rb1.2.1&q=80&w=600" />
</div>
<script>
let nav = document.getElementById("navigation-bar");
let sticky = nav.offsetTop;
window.onscroll = function() {sticker()};
function sticker() {
   if (window.pageYOffset >= sticky) {
      nav.classList.add("sticky")
   } else {
      nav.classList.remove("sticky");
   }
}
</script>
</body>
</html>

आउटपुट

यह निम्नलिखित परिणाम देगा -

CSS के साथ ऑन स्क्रॉल फिक्स्ड नेविगेशन बार कैसे बनाएं?

CSS के साथ ऑन स्क्रॉल फिक्स्ड नेविगेशन बार कैसे बनाएं?


  1. कैसे सीएसएस के साथ स्क्रॉल पर एक ढाल पृष्ठभूमि रंग बनाने के लिए?

    स्क्रॉल पर एक ग्रेडिएंट बैकग्राउंड कलर बनाने के लिए, कोड इस प्रकार है - उदाहरण <!DOCTYPE html> <html> <head> <style>    body {       height: 250vh;       color: white;       font-family: "Segoe UI", Tahoma, Gene

  1. सीएसएस के साथ एक निश्चित/चिपचिपा पाद लेख कैसे बनाएं?

    CSS के साथ निश्चित पादलेख बनाने के लिए, कोड इस प्रकार है - उदाहरण body{ font-family:Segoe UI , ताहोमा, जिनेवा, वर्दाना, सेन्स-सेरिफ़; } .पाद लेख {फ़ॉन्ट-आकार:20px; स्थिति:निश्चित; बाएं:0; नीचे:0; चौड़ाई:100%; पृष्ठभूमि-रंग:आरजीबी (50, 6, 100); रंग सफेद; पाठ-संरेखण:केंद्र; }फिक्स्ड/स्टिकी फूटर उदाहर

  1. सीएसएस के साथ तीर कैसे बनाएं?

    सीएसएस के साथ तीर बनाने के लिए, कोड इस प्रकार है - उदाहरण <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1" /> <style>    body {       font-family: "Segoe UI", Tahoma,