The HTML navbar seems to have a mind of its own, disappearing and shifting around unpredictably as I zoom in or resize

WHEN DISPLAYING THIS CODE, IT IS ADVISED TO VIEW IN FULL PAGE MODE

This code includes navigation, header, and styling elements. However, when the browser is zoomed in or out, the navbar tends to move around and eventually disappears off the screen if window size is changed.

I am looking for a solution to make my navbar responsive without moving around when the page is zoomed in. Any assistance would be highly appreciated.


/* ---------- Navigation ---------- */

nav{
  width: 100%;
  height: 60px;
  font-weight: bold;
  color: white;
    position: absolute;
    bottom: 500px;
    left: -250px;
}

nav ul{
  float: right;
}

nav ul li{
  float: left;
  list-style: none;
  position: relative;
}

nav ul li a{
  font-family: arial;
  color: black;
  font-size: 20px;
  padding: 22px 14px;
  display: block;
  text-decoration: none;
}

nav ul li ul{
  display: none;
  position: absolute;
  background: #4f88bd;
  padding: 10px;
  border-radius: 0px 0px 4px 4px;
}

nav ul li:hover ul{
  display: block;
}

nav ul li ul li{
  width: 180px;
  border-radius: 4px;
}

nav ul li ul li a{
  padding: 8px 14px;
}
    
nav ul li ul li a:hover{
  background: #26227d;
}

/* ---------- Navigation ---------- */

/* ---------- Header ---------- */

header{
  background: #35424a;
  color: #ffffff;
  padding: 20px;
  min-height: 70px;
    text-align: center;
}

header h1{
    font-size: 50px;
    text-align: center;
}

header h1 a{
    text-decoration: none;
    color: white;
}

/* ---------- Header ---------- */
            
<header>
    <h1><a href="index.html">Olympic Class Liners</a></h1>
        <nav>
            <ul>
                <li><a href="#">Olympic</a>
                    <ul>
                        <li><a href="olympic-overview.html">Overview</a></li>
                        <li><a href="olympic-crew.html">Crew</a></li>
                        <li><a href="olympic-decks.html">Decks</a></li>
                        <li><a href="olympic-passengers.html">Passengers</a></li>
                    </ul>
                </li>;

                /* Additional List Items Here */

            </ul>
        </nav>
</header>

Answer №1

To make your website responsive, implement media queries in your CSS code. Here is an example:

/* Define Media Queries */

   @media (max-width: 1024px) {
       .nav li { width: 100%; }
       .nav .dropdown ul { display:none; }
       .nav .open ul { display: block; }

       .nav-collapse .nav > li > a, .nav-collapse .dropdown-menu a {
           text-align: center;
       }
   }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to turn off the shadow on just one side?

Is there a way to remove the shadow in the red area below? I have come across similar questions but unsure how to implement those solutions here. Live Demo: http://jsfiddle.net/xFa9M/ CSS:- #list li{ border: 2px solid black; border-top-width: 1px; borde ...

Using a MySQL statement within a conditional statement

Looking to modify this code to display different information based on the values retrieved, here is the current code: $sql_doublecheck = mysql_query("SELECT * FROM adminpage WHERE setting='main' AND close_site='1'"); $doublecheck = mys ...

Steps for placing an image within the boundary of a rectangular div

My div has a width of approximately 730px and a height of 50px. I am looking to place an image at the bottom of the div, exactly where its height ends - after 50px. I have been considering a query to append the image at the bottom. One solution could be ...

Overlap of Navigation and Logo Divs on Mobile Website

Trying to optimize my website for mobile at coveartschildcare.com, but the header divs keep overlapping and nothing I do seems to fix it. Here's the CSS code I'm currently using: @media only screen and (min-device-width: 320px) and (max-devi ...

HTML: A peculiar table setup with an image displayed on the right side and text aligned to the left side. Strangely, the

Just starting out and seeking assistance <table style="border:none" cellpadding="0" cellspacing="0"> <tbody> <tr> <td style="border:none" valign="top" vertical-align:"top"; width="20%"> <div><img class= ...

Google Extension PHP Plugin

Is it feasible to integrate a PHP file into a Google Extension for Chrome? I've been exploring the idea of creating an extension and most resources only mention HTML, CSS, and JavaScript. Any guidance on using PHP in the extension would be highly valu ...

What is the best way to emphasize this specific section of text?

Looking for help with my tumblr template. I have the following block of code: {block:IfNotEndlessScroll}{block:Pagination}{block:PreviousPage}Previous Page{/block:PreviousPage} {block:NextPage}Next Page{/block:NextPage}{/block:Pagination}{/block:IfN ...

Adjust the source of the HTML5 video tag based on the orientation of an iPad

I am currently coding an HTML5 page specifically for iPad Mobile Safari, which includes a video tag for embedding video files. I have successfully implemented CSS3 media queries to determine the orientation of the iPad. My next challenge is to dynamically ...

Please ensure you tick the checkbox corresponding to the item number

I'm trying to select a checkbox for a specific item number: List<WebElement> returnItemContainer = driver .findElements(By.xpath("//ul[@class='return-item-select-container']")); int numberOfElements = driver.findEleme ...

Chaining fade in and slide effects on a div element

I am attempting to display a <div> named settings when a button is clicked. The intention is for it to fade in and then slide towards the right side of the screen, originating from the left side. Progress so far: The HTML <div id="settings" ng- ...

The active link color for navigation in Bootstrap 4

I am trying to update the active menu links to display in green on my website. Despite various attempts, I have not been successful in changing the color. Can anyone provide guidance on how to proceed? My website is built with Bootstrap 4 and mdbootstrap. ...

The PHP code I wrote will be executed on the subsequent HTML page, not the one currently being displayed

I have a school project where I am creating a quiz-game web page. Each question will have 4 possible answers. The questions, along with their 4 answer choices and the correct answer, are randomly selected from a database. However, I am facing an issue w ...

What is preventing me from extracting all information from online shopping sites?

Recently, I've been tackling a project that involves scraping data from various e-commerce websites. However, I've encountered difficulties in extracting the desired information from these sites. For instance, when attempting to scrape all the li ...

Creating a basic popup with jQuery: A step-by-step guide

Currently in the process of creating a webpage. Wondering how to create a popup window with an email label and text box when clicking on the mail div? ...

Is it possible for JQuery to interact with an Access database for both reading and writing

Is it possible to utilize Jquery to establish a link with a Microsoft Access database? I have been exploring this possibility but haven't found any relevant information. This database won't be used for a production site, but rather for a small gr ...

Implement jQuery to dynamically assign an "Active" class to tab elements based on the current page being loaded

INQUIRIES I have include: How do I apply a class to an element using jQuery, or any other method, for the active tab? Ensure that the dropdown tab appearing is the one containing the active tab, not always the Company one. In essence, I want the ac ...

What is the best method for restricting the visibility of an animation to specific regions within an SVG?

I am seeking assistance with adding a "shine" animation to my SVG. I want the animation to only appear within specific parts of the SVG, but I'm uncertain about how to achieve this. Below is what I have accomplished so far. The aim is for the white ...

Creating a Sticky Header and Footer with Responsive Design: Ensuring Content Div Expansion between Them

Greetings. I am working on creating a simple responsive HTML layout as described below: HTML: <div id="header"></div> <div id="content"></div> <div id="footer"></div> CSS: #header{ wi ...

Angular 4 allows the addition of an image from right to left upon clicking

I've been working on angular 4 and I've successfully implemented the functionality of adding flags. However, the issue is that the flags are currently appearing from left to right. What I'm aiming for is to have the images appear from right ...

Convert the button element to an image

Can someone please explain how to dynamically change a button element into an image using javascript when it is clicked? For instance, changing a "Submit" button into an image of a check mark. ...