Floating top menu

I am currently working on developing a sticky navigation bar that remains in place when scrolling down. However, I encountered an issue where using position: fixed; caused the text to overlap. Unfortunately, I am unable to use jQuery as my professor has advised against it.

   <html>
    <head> <title> My Portfolio </title> 
    <link rel="stylesheet" type = "text/css"
    href="stylesheet.css"> </head>
    <body>
    <ul>
    <a href="Index.html"> Home </a>
    <a href="About.html" > ABOUT </a >
    <a href="Projects.html"  >PROJECTS </a >
    <a href="Resume.html" >RESUME </a >
    <a href="Gallery.html" > GALLERY </a >
    <b> </b>
    </body>
    </html>

CSS

body{
background-position:fixed;
background-repeat:repeat-x;
background-color:white;
font-family:Arial;
font-size:20px;
}

a{
color:#1b1b1b;
TEXT-DECORATION: NONE;
position:fixed;
z-index:2;



}
b{
top:0;
height:30px;
width: 100%;
background:white;
text-align:left;
position:fixed;
z-index:1;
}

Answer №2

Your code has a few issues that need to be addressed. Firstly, the <ul> tag is missing its closing tag, which can cause inconsistencies in rendering across different browsers. Additionally, remember that <ul></ul> is an unordered list and should have list items (<li></li>).

Another issue is misunderstanding the purpose of the <b> tag. By default, <b></b> applies bold styling to text, not as a stand-alone element.

<ul>
    <li><a href="#">LINK</a></li>
    <li><a href="#">LINK</a></li>
    <li><a href="#">LINK</a></li>
    <li><b><a href="#">BOLD LINK</a></b></li>
</ul>

The main issue lies in incorrectly applying position: fixed; to your links instead of their container. To achieve the desired effect, set the position of the container (e.g., <ul>) to fixed and use position: relative; for individual links inside it. This way, each link will be positioned relative to the container.

For reference, check out this example: http://jsfiddle.net/7LTqQ/.

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

Concealing a div element while ensuring that it does not obscure any of its contents

There is a challenge I'm facing that I need help solving. I am using a shop script that only allows me to edit the CSS file. Within this setup, there is a div with a background image and inside there is a normal image: <style type="text/css"> ...

Retrieving identical information from multiple HTML files

Suppose I have multiple HTML pages from different websites, all with the same content. I am looking to extract this information in a versatile way so that I only need to create a few data extractors (ideally just one). Let's say the fields are (using ...

Fixed-top navigation bar in Bootstrap

Currently working on constructing a Single Page Application (SPA) using Bootstrap, where the navbar is fixed-top. Encountering an issue where content gets cut off by the navbar unless setting the element margin-top to 58px. Although using the specified sty ...

What is the source of these additional pixels that appear when percentages are used for defining height?

I have been working on implementing a sticky footer that I've successfully used in the past for various websites. You can find the link to the original method here: However, this time I am facing a challenge as I want to make the footer more responsi ...

Error in Javascript: Required variable missing for Sendgrid operation

I am facing an issue while attempting to send an email using sendgrid. Whenever I execute the function, it gives me an error saying "Can't find variable: require". Despite my efforts to search for a solution online, I have not been able to resolve thi ...

Select2 Dropdown Options Do Not Update Background Color

I am currently implementing the Select2 Input CSS/jQuery framework from to assist me in handling multi-select boxes. However, I am facing difficulty in changing the background color of the results when the select box is clicked. To provide a better under ...

Change the selection so that only the initial one appears in gray

Is there a way to make the text inside a select field gray out when the first option is selected? Can this be accomplished with just CSS or does it require JS? I have attempted altering the style of the first option, but it only affects the text color in ...

Can the ~ and + selectors be combined simultaneously for styling elements?

Imagine a scenario where you have HTML code like this: <input type="checkbox" id='hello'> <label for="hello"> hello </label> <ul> <li>A</li> <li>B</li> <li>C</li> </ul> Alo ...

Tips for organizing the outcome of a seamless web scraping operation with Apify and Puppeteer

Extracting data from a table on the designated URL using Apify and Puppeteer is my current goal: https://en.wikipedia.org/wiki/List_of_hedge_funds The desired outcome should be an array of objects. Each element in the array must represent a <tr> ro ...

Having trouble applying CSS to SVG icons from defs file in Webkit Browser

I've been tinkering with a project that incorporates SVG icons, hoping to style them using CSS for various scenarios and hover effects. However, my attempts are falling short in Webkit, while Firefox is displaying the icons as intended: http://codepe ...

Utilizing Loops to Generate Unique CSS Designs on an HTML Page

View reference image ->Take a look at the reference image provided. ->In the image, a for loop is used to create box designs and displayed above. ->The goal is to change the background color and border color of all boxes using a single HTML cla ...

How can I ensure my webpage displays properly on different devices using HTML?

I have been trying to make my code responsive by adding media queries, but I am struggling to get it to work with the current setup. I even attempted setting the width to 100%, but still facing issues. I would really appreciate a simple explanation on how ...

Unable to create a clickable image

My approach involves using asp:Hyperlink controls to create an image that acts as a link. Here is the sample code in both aspx and C#: <asp:HyperLink ID="mainInteractiveFileLink" runat="server"> </asp:HyperLink> C# mainInteractiveFileLink ...

What could be causing my slider to malfunction?

No errors are being returned by the console. Currently utilizing Unslider. The setup includes: <div class="slider"> <ul> <li><img src="img/one.jpg" alt=""></li> <li><img src="img/one.jpg" ...

I am looking to incorporate an OVG video onto my website

I have a video in OVG format that I want to add to my website. Since I am not very familiar with this file type, I'm concerned about how it will perform across different web browsers. I know that Firefox can play the file, but I'm unsure about In ...

The input field must only accept numbers with decimal points

I have developed a dynamic HTML table that includes various input controls. I am looking to restrict input to only decimal values with two digits after the point. For example: 1111.22 , 44445454.33 Here is the HTML code snippet: <div id="divdynam ...

What is the method for retrieving the value from a text input using JavaScript?

let userInput = document.getElementById('myFieldId'); console.log(userInput.value); <!DOCTYPE html> <html> <head> </head> <body> <input type="text" id="myFieldId"/> <script src="main.js">< ...

What is the process for enabling a deactivated hyperlink?

Trying to figure out how to create a link that will only activate when a specific value is present. Let's say I have a link like this: a(class="nav-link" id="signal_" style="pointer-events: none" href="/goToStreamingPage") <i class="fas fa-signal" ...

What is the most efficient way to display a dynamic alphabetical order list?

sample code: <table width="100%" cellspacing="0" cellpadding="0" border="0" style="line-height: 1.7;"> <tbody> <?php $this->db->select('*'); $this->db->from('cm_options'); ...

Guide on setting a session variable upon clicking an <a> hyperlink

Having this issue where I need to set a session variable when clicking on a regular link like: <a href="home" name="home">home</a> From my research, it seems PHP cannot capture the click event in order to set a session variable. I've he ...