Jump to content

ike

Members
  • Content Count

    10
  • Joined

  • Last visited

Community Reputation

0 Neutral

About ike

  • Rank
    Newbie

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. I have a sticky navbar which works fine until I add an image to my image box which at that point the sticky doesn't kick in until you scroll past the image. Any ideas as to what could be the cause of this it's driving me crazy? At least it's a short trip for me! <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> body { margin: 0; font-size: 28px; font-family: Arial, Helvetica, sans-serif; } .header { background-color: #f1f1f1; padding: 30px; text-align: center; } #navbar { overflow: hidden; background-color: #333; } #navbar a { float: left; display: block; color: #f2f2f2; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; } #navbar a:hover { background-color: #ddd; color: black; } #navbar a.active { background-color: #4CAF50; color: white; } .content { padding: 16px; min-height: 1000px; } .sticky { position: fixed; top: 0; width: 100%; } .sticky + .content { padding-top: 60px; } .imagebox{ position: relative; width: 100%; height: auto; padding: 0px auto; margin: 0px auto; } .loginbox{ position: absolute; float: right; top: 25px; right: 25px; width: 200px; height: 200px; padding: 15px; background-color: rgba(0, 0, 0, 0.25); } </style> </head> <body> <div class="header"> <h2>Scroll Down</h2> <p>Scroll down to see the sticky effect.</p> </div> <div id="navbar"> <a class="active" href="javascript:void(0)">Home</a> <a href="javascript:void(0)">News</a> <a href="javascript:void(0)">Contact</a> </div> <div class="imagebox"> <div class="loginbox "></div> </div> <div class="content"> <h3>Sticky Navigation Example</h3> <p>The navbar will stick to the top when you reach its scroll position.</p> <p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.</p> </div> <script> window.onscroll = function() {myFunction()}; var navbar = document.getElementById("navbar"); var sticky = navbar.offsetTop; function myFunction() { if (window.pageYOffset >= sticky) { navbar.classList.add("sticky") } else { navbar.classList.remove("sticky"); } } </script> </body> </html>
  2. I've got it working to some degree but not sure it is best practice. Just curious Is what I've done suitable? I added position: static; to the login div on screen resize and gave it enough top margin to move below the image div. It was overlapping the body-content div so I gave the body-content div enough top margin to move below the login div. Here is my new code. <style> *{ padding: 0px auto; margin: 0px auto; } img { max-width: 100%; height: auto; } div.image-box { position: relative; border: 1px solid black; width: 100%; height: 500px; padding: 0px auto; margin: 0px auto; } div.login { position: absolute; float: right; top: 25px; right: 25px; width: 175px; height: 175px; padding: 15px; background-color: white; border: 2px solid red; background-color: rgba(0, 0, 0, 0.25); } div.body-content{ width: 100%; height: 500px; background-color: #333; } @media screen and (max-width: 640px) { div.body-content{ margin-top: 275px; width: 100%; height: 500px; background-color: #333; } div.mobile-collapse { width: auto; margin-right: 0px; float: none; } div.image-box { border: 1px solid black; width: 100%; height: 250px; padding: 0px auto; margin: 0px auto; } div.login { position: static; right: 25px; width: 175px; height: 175px; padding: 15px; margin: 275px auto 0px auto; background-color: white; border: 2px solid red; background-color: rgba(0, 0, 0, 0.25); } } </style> </head> <body> <div class="image-box"> <div class="login mobile-collapse">This is my div</div> </div> <div class="body-content"></div> </body> </html>
  3. I have a login script I want to place over an image which I believe I have done. However, I would like to move the login script div below the image div on small screens. I can accomplish this with separate divs using mobile-collapse but can seem to make it work with the div inside the other div. Any suggestions would be great! Thanks!! <!doctype html> <html> <head> <META content="IE=11.0000"> <META http-equiv="X-UA-Compatible"> <META charset="utf-8"> <META http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <META name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0"> <TITLE>DIV TEST</TITLE> <style> *{ padding: 0px auto; margin: 0px auto; } img { max-width: 100%; height: auto; } div.image-box { position: relative; border: 1px solid black; width: 95%; height: 500px; padding: 0px auto; margin: 0px auto; } div.login { position: absolute; float: right; top: 25px; right: 25px; width: 175px; height: 175px; padding: 15px; background-color: white; border: 2px solid red; background-color: rgba(0, 0, 0, 0.25); } @media screen and (max-width: 780px) { div.mobile-collapse { width: auto; margin-right: 0px; float: none; } div.image-box { position: relative; border: 1px solid black; width: 90%; height: 250px; padding: 0px auto; margin: 0px auto; } } </style> </head> <body> <div class="image-box"> <div class="login mobile-collapse">Login Div</div> </div> </body> </html>
  4. ike

    Dropdown menu not working with sticky navbar

    I could have sworn I tried that but must have mucked it up somehow as it working now along with the right arrow. Many thanks! I see most navigation menus are made up of unordered lists and list items. Are there benefits of creating it that way opposed to the div structure I used?
  5. ike

    Dropdown menu not working with sticky navbar

    I created a sub menu on one of my dropdowns which seems to be working. However, i'm struggling on how the get the Sub Menu Text aligned to the left. Currently it's centered and I'd like it to line up with the other links. Also, is there a way to have an arrow pointing to the right on the Sub Menu? <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <title></title> <style> body { margin:0; font-family: Arial; } .header{ width: 100%; height: 125px; background-color: #999; } .body-content{ width: 100%; min-height: 1025px; background-color: #fff; } .footer{ width: 100%; height: 175px; background-color: #000; } .topnav { background-color: #333; overflow: ; } .topnav::after { clear: both; content: ""; display: block; } .topnav a { float: left; display: block; color: #f2f2f2; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; } .active { background-color: ; color: white; } .topnav .icon { display: none; } .dropdown { float: left; overflow: ; } .dropdown .dropbtn { font-size: 17px; border: none; outline: none; color: white; padding: 14px 16px; background-color: #333; font-family: inherit; margin: 0; } .dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; } .dropdown-content a { float: none; color: black; padding: 12px 16px; text-decoration: none; display: block; text-align: left; } .subdropdown .subdropbtn { font-size: 17px; border: none; outline: none; color: white; padding: 14px 16px; background-color: #555 ; font-family: inherit; width: 160px; } .subdropdown-content { display: none; position: absolute; height: 0px; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; } .subdropdown-content a { float: none; color: black; padding: 14px 16px; text-decoration: none; display: block; text-align: left; position: relative; top: -48px; left: 160px; background-color: #f9f9f9; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; } .topnav a:hover, .dropdown:hover .dropbtn { background-color: #555; color: white; } .dropdown-content a:hover { background-color: #ddd; color: black; } .subdropdown-content a:hover { background-color: #ddd; color: black; } .dropdown:hover .dropdown-content { display: block; } .subdropdown:hover .subdropdown-content { display: block; } /* Page content */ .content { padding: 16px; } /* The sticky class is added to the navbar with JS when it reaches its scroll position */ .sticky,.topnav.responsive.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; } @media screen and (max-width: 600px) { .topnav a:not(:first-child), .dropdown .dropbtn { display: none; } .topnav a.icon { float: right; display: block; } } @media screen and (max-width: 600px) { .topnav.responsive {position: relative;} .topnav.responsive .icon { position: absolute; right: 0; top: 0; } .topnav.responsive a { float: none; display: block; text-align: left; } .topnav.responsive .dropdown {float: none;} .topnav.responsive .dropdown-content {position: relative;} .topnav.responsive .dropdown .dropbtn { display: block; width: 100%; text-align: left; } } </style> </head> <body> <div class="header"></div> <div class="topnav" id="myTopnav"> <a href="home2.html" class="active">Home</a> <a href="a2.html">About</a> <div class="dropdown"> <button class="dropbtn">Products <i class="fa fa-caret-down"></i> </button> <div class="dropdown-content"> <a href="plone.html">Link 1</a> <a href="#">Link 2</a> <a href="#">Link 3</a> </div> </div> <div class="dropdown"> <button class="dropbtn">Services <i class="fa fa-caret-down"></i> </button> <div class="dropdown-content"> <a href="slone.html">Link 1</a> <a href="#">Link 2</a> <div class="subdropdown"> <button class="subdropbtn">Sub Menu <i class="fa fa-caret-down"></i> </button> <div class="subdropdown-content"> <a href="smlone.html">Sub Menu Link 1</a> <a href="#">Sub Menu Link 2</a> <a href="#">Sub Menu Link 3</a> </div> </div> </div> </div> <a href="news2.html">News</a> <a href="c2.html">Contact</a> <a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">&#9776;</a> </div> <div class="body-content"> <div style="padding-left:16px"> <h2>Home</h2> <p>Resize the browser window to see how it works.</p> <p>Hover over the dropdown button to open the dropdown menu.</p> </div> </div> <div class="footer"></div> <script> function myFunction() { var x = document.getElementById("myTopnav"); if (!x.classList.contains("responsive")) { x.classList.add("responsive"); } else { x.classList.remove("responsive"); } } </script> <script> // When the user scrolls the page, execute myFunction window.onscroll = function() {myFunctionSticky()}; // Get the topnav var topnav = document.getElementById("myTopnav"); // Get the offset position of the navbar var sticky = topnav.offsetTop; // Add the sticky class to the navbar when you reach its scroll position. Remove "sticky" when you leave the scroll position function myFunctionSticky() { if (window.pageYOffset >= sticky) { topnav.classList.add("sticky") } else { topnav.classList.remove("sticky"); } } </script> </body> </html>
  6. ike

    Dropdown menu not working with sticky navbar

    Your suggestion has things working properly now. Thank you very much! I hope I can understand things better someday, as the smallest changes can make such a dramatic impact. Forgot we are going to need a sub menu on one of the dropdowns. Any chance of creating a sub menu with in the current dropdown menu? Seems like I might have to switch to a different menu type using unordered list & li's to accomplish this which will probably blow everything apart.
  7. ike

    Dropdown menu not working with sticky navbar

    I finally got it working by giving the .topnav a fixed height and removing the overflow: hidden;. .topnav { background-color: #333; overflow: ; height: 48px; } However, now if you reduce the screen size when you click the menu icon the bottom three menu items do not have the dark background color.
  8. ike

    Dropdown menu not working with sticky navbar

    Thanks a bunch. I understand this change, /* The sticky class is added to the navbar with JS when it reaches its scroll position */ .sticky,.topnav.responsive.sticky { position: fixed; top: 0; width: 100%; } but would never have figured out the changes you made to the first script. The dropdowns still will not work once the navbar gets stuck unless you reduce the screen size so the responsive kicks in. I thought it was the overflow: hidden; on the .dropdown but I removed that and it still does not work. Any suggestions on that? Thanks again for all your help!
  9. ike

    Dropdown menu not working with sticky navbar

    Thanks for the replay. I made the suggested changes and it kind of works. If reduce the page width and scroll all the way to the bottom the navbar moves to the top of the page however, when I click the menu icon, the menu disappears or jumps out of view now. If I reduce the width but do not scroll all the way to the bottom of the page and click on the menu icon the dropdown works.
  10. I'm trying to use the responsive navbar and sticky code but the dropdown will not show when the sticky kicks in. I tried removing the overflow: hidden; on the .dropdown but that didn't help. Also I can't get the responsive menu to work, seems like there is a conflict with the two different scripts. <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>stickydropdown.html</title> <style> body { margin:0; font-family:Arial } .header{ width: 100%; height: 125px; background-color: #999; } .body-content{ width: 100%; min-height: 1025px; background-color: #fff; } .footer{ width: 100%; height: 175px; background-color: #000; } .topnav { background-color: #333; overflow: hidden; } .topnav a { float: left; display: block; color: #f2f2f2; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; } .active { background-color: ; color: white; } .topnav .icon { display: none; } .dropdown { float: left; overflow: ; } .dropdown .dropbtn { font-size: 17px; border: none; outline: none; color: white; padding: 14px 16px; background-color: #333; font-family: inherit; margin: 0; } .dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; } .dropdown-content a { float: none; color: black; padding: 12px 16px; text-decoration: none; display: block; text-align: left; } .topnav a:hover, .dropdown:hover .dropbtn { background-color: #555; color: white; } .dropdown-content a:hover { background-color: #ddd; color: black; } .dropdown:hover .dropdown-content { display: block; } /* Page content */ .content { padding: 16px; } /* The sticky class is added to the navbar with JS when it reaches its scroll position */ .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; } @media screen and (max-width: 600px) { .topnav a:not(:first-child), .dropdown .dropbtn { display: none; } .topnav a.icon { float: right; display: block; } } @media screen and (max-width: 600px) { .topnav.responsive {position: relative;} .topnav.responsive .icon { position: absolute; right: 0; top: 0; } .topnav.responsive a { float: none; display: block; text-align: left; } .topnav.responsive .dropdown {float: none;} .topnav.responsive .dropdown-content {position: relative;} .topnav.responsive .dropdown .dropbtn { display: block; width: 100%; text-align: left; } } </style> </head> <body> <div class="header"></div> <div class="topnav" id="myTopnav"> <a href="stickydropdown.html" class="active">Home</a> <div class="dropdown"> <button class="dropbtn">Products <i class="fa fa-caret-down"></i> </button> <div class="dropdown-content"> <a href="plinkone.html">Link 1</a> <a href="#">Link 2</a> <a href="#">Link 3</a> </div> </div> <div class="dropdown"> <button class="dropbtn">Services <i class="fa fa-caret-down"></i> </button> <div class="dropdown-content"> <a href="slinkone.html">Link 1</a> <a href="#">Link 2</a> <a href="#">Link 3</a> </div> </div> <a href="a.html">About</a> <a href="news.html">News</a> <a href="c.html">Contact</a> <a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">&#9776;</a> </div> <div class="body-content"> <div style="padding-left:16px"> <h2>Home</h2> <p>Resize the browser window to see how it works.</p> <p>Hover over the dropdown button to open the dropdown menu.</p> </div> </div> <div class="footer"></div> <script> function myFunction() { var x = document.getElementById("myTopnav"); if (x.className === "topnav") { x.className += " responsive"; } else { x.className = "topnav"; } } </script> <script> // When the user scrolls the page, execute myFunction window.onscroll = function() {myFunction()}; // Get the topnav var topnav = document.getElementById("myTopnav"); // Get the offset position of the navbar var sticky = topnav.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) { topnav.classList.add("sticky") } else { topnav.classList.remove("sticky"); } } </script> </body> </html>
×