Tips for keeping the menu in place: ensure it remains fixed and unaltered when adjusting the browser size or zoom level

Q:

I have a navigation menu that seems to change position every time I adjust the browser zoom. How can I make the menu stay fixed in its place?

The CSS:

ul#topnav
{
    margin-left:0;

    margin-bottom:50px;
    margin-top:5px;
    padding: 0;
    float: right;
    width: 800px;
    list-style: none;
    position: relative; /*--Set relative positioning on the unordered list itself - not on the list item--*/
    font-size: 1.2em;
    background:#CC6A11; /*url(topnav_stretch.gif) repeat-x;*/
}
ul#topnav li
{
    float: right;
    margin: 0;
    padding: 0;
    border-right: 1px solid #555; /*--Divider for each parent level links--*/
}
ul#topnav li a
{
    padding: 10px 15px;
    display: block;
    color: #f0f0f0;
    text-decoration: none;
}
ul#topnav li:hover
{
    background: #1376c9 url(../images/topnav_active.gif) repeat-x;
}

ul#topnav li span
{
    float: right;
    padding: 10px 0;
    position: absolute;
    left: 0;
    top: 35px;
    display: none; /*--Hide by default--*/
    width: 800px;
    background: #1376c9;
    color: #fff; /*--Bottom right rounded corner--*/
    -moz-border-radius-bottomright: 5px;
    -khtml-border-radius-bottomright: 5px;
    -webkit-border-bottom-right-radius: 5px; /*--Bottom left rounded corner--*/
    -moz-border-radius-bottomleft: 5px;
    -khtml-border-radius-bottomleft: 5px;
    -webkit-border-bottom-left-radius: 5px;
}
ul#topnav li:hover span
{
    display: block;
}
/*--Show subnav on hover--*/
ul#topnav li span a
{
    display: inline;
}
/*--Since we declared a link style on the parent list link, we will correct it back to its original state--*/
ul#topnav li span a:hover
{
    text-decoration: underline;
}

.aspx

<div style="  margin-right:20%" >
            <ul id="topnav">
                <li><a href="frm_AssistantCV.aspx">الرئيسية</a></li>
                <li><a href="#">النشاط التعليمي</a> <span><a href="frm_TeachingLoad.aspx">العبأ التدريسي</a>
                    | <a href="frm_EducationalActivities.aspx">الأنشطة التعليمية</a> | <a href="frm_EducationalActivitiesDirectly.aspx">
                        الأنشطة التعليمية المباشرة</a> </span></li>
                <li><a href="#">النشاط العلمي</a> <span><a href="frm_ScientificActivity.aspx">النشاط
                    العلمي 1</a> | <a href="frm_ScientificActivity2.aspx">النشاط العلمي 2</a> | <a href="frm_ScientificActivity3.aspx">
                        النشاط العلمي 3</a> </span></li>
                <li><a href="frm_ManagementActivity.aspx">النشاط الاداري</a></li>
                <li><a href="frm_StudentActivities.aspx">االاشتراك في أنشطة طلابية</a></li>
                <li><a href="frm_Evaluation.aspx">التقييم العام</a></li>
                <li><a href="LoginPage.aspx">خروج</a></li>
            </ul>
        </div>

I implemented this menu

Answer №1

Follow these two simple steps to resolve your issue!

1) Eliminate the margin-right from the div.

Previous :<div style="  margin-right:20%" >

Modified: <div>

2) Make the following changes in your topnav css:

ul#topnav {
    background: none repeat scroll 0 0 #CC6A11;
    float: right;
    font-size: 1.2em;
    list-style: none outside none;
    margin-bottom: 50px;
    margin-top: 15px;
    padding: 0;
    position: relative;
    text-align: left;
}

This should effectively address your problem!

Answer №2

Expect an increase in size, but prevent it from moving by swapping out:

<div style="  margin-right:20%; width:100%" >

with

<div style="position:absolute; top: 0px; left: 20px;" >

Answer №3

It's important to include the meta viewport tag in your HTML files for optimal display on various devices. Additionally, applying the 'position: fixed' attribute in your menu's CSS will keep it sticky and floating as users scroll down the page.

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

You cannot invoke this expression while destructuring an array of React hooks in TypeScript

Within my React TypeScript component, I have several fields that check a specific condition. If the condition is not met, the corresponding field error is set to true in order to be reflected in the component's DOM and prevent submission. However, whe ...

Utilizing document.write() for displaying markup content

I have an inline SVG stored as a variable on my webpage and I am making some changes to it. How can I display viewText on the page (not the SVG image) with the modifications? What is the best way to make viewText appear on the page? For instance: ...

The console is reporting an error stating it cannot read the charCodeAt property

<script> var str=prompt('please enter a string'); var a= str.split(''); for (j=0; j<str.length; j++){ for(i=j; i<str.length; i++) { if(a[i].charCodeAt(0) > a[i+1].charCodeAt(0)) { var b= a[i]; a[i]=a[i+ ...

Issue with grunt-crx task detected

In my Gruntfile, I've integrated the grunt-crx task as shown below: crx: { packExtension: { src: "../build/unpacked", dest: "../build/dist" } } Whenever I execute the crx task on its ow ...

Exploring the capabilities of ASP filtering with AJAX and traditional requests

I am currently working on an asp webpage in Net4.0 and facing a limitation with the inability to use async methods in this version. The page includes an ajax container called UpdatePanel, within which there is a button. Upon clicking this button, the page ...

Is it possible to make jQuery dialog text behave like a JavaScript prompt?

Hello there, I have a query! I'm looking to allow users to easily copy text within a dialog window by simply pressing CTRL + C. Is this possible, and if so, how can it be achieved? An instance of this functionality is seen in the javascript alert pr ...

CSS3 Rounded Corners

What is the most effective method to create this style of border using only CSS3? PS: The width should be 100%, matching the size of the screen. ...

What steps do I need to take to develop a CLI application similar to ng, that can be installed globally on the system

Upon installing npm i ng -g How does the system determine the installation path? I am interested in creating an application that can be installed and executed similarly. ...

The Correct Way to Implement Google ReCaptcha

I've developed a PHP contact form that performs validation using AJAX/JSON on the server side. The errors are then passed to Javascript for display and adjustments to the HTML/CSS. My challenge now is to integrate Google ReCaptcha with AJAX validatio ...

Choose the list item below

I'm working on a website that includes a select list with images. Here's what I have so far: When I choose an image from the list, it should display below. <?php // Establish database connection $con=mysqli_connect("******","***","*** ...

Create an array using modern ES6 imports syntax

I am currently in the process of transitioning Node javascript code to typescript, necessitating a shift from using require() to import. Below is the initial javascript: const stuff = [ require("./elsewhere/part1"), require("./elsew ...

Create a function that takes an array as input and retrieves the element in the array that corresponds to the specified question

To solve this problem, I'm tasked with creating a function called findAnswers(answers, questions). The function should return the item in the array that corresponds to the given question. If none of the student's answers match the question, the f ...

problem with overflow in HTML and CSS opera browser

My gradient is not displaying properly in the Opera browser. Can anyone help me troubleshoot? Check out the code on jsfiddle for reference:) http://jsfiddle.net/KtDTK/7/ <div class="product_1"> <div class="product_block"> <div cla ...

transforming bootstrap 3 column into bootstrap 2

Is it possible to achieve dynamic column adjustment in Bootstrap 2 like the example shown here? I want the layout to display 4 columns when the window is wide enough, but switch to 2 columns when the width of the window decreases. Since Bootstrap 2 only us ...

What could be causing this React/Javascript object to be undefined?

I've been attempting to convert this JSON into JavaScript objects, but all my efforts have resulted in undefined values. The objects simply won't work as intended. Here is the code I'm using with the getStaticProps method to extract objects ...

Send error messages directly to the client side or retrieve status codes and messages

When responding to an AJAX request, encountering an app error like data validation failure can be tricky. How can we effectively communicate this to the user? 1. Returning a Status Code and Fetching Message with JS $.ajax(options).done(function(response) ...

Issues with uploading files on iOS devices when using ReactJS

Encountering an issue with uploading photos on iPhone in a Reactjs app. The problem seems to be specific to iOS as the code works fine on Android and computer. Below are the codes for better debugging. "use client" import Link from "next/l ...

What is the best way to fetch data before a component is rendered on the screen?

I am facing an issue with fetching data from a local server in Node. When I try to render the component, the array 'users' from the state appears to be empty, resulting in no users being displayed on the screen as intended. What's strange is ...

Encountering a frustrating internal server error 500 when attempting to insert values from JavaScript into SQL Server within Visual Studio

Here is a JavaScript code that calls a C# webmethod: var _data = { '_mStart': document.getElementById("St_Period").value, '_mEnd': document.getElementById("En_Period").value }; $.ajax({ type: "POST", url: "maps.aspx/my ...

I would like to display the array in several separate tags, instead of just one tag

The json array data has been successfully placed in the functionSupplement variable. If you were to output this <p>functionSupplement </p>, the result would look something like this. Is there a way for me to modify my code so that it functions ...