I have noticed that there are more clickable elements in my website's Navigation Bar than I intended. What is the reason behind their presence?

Currently enrolled in a university program in the UK, I am tasked with creating a website using HTML and CSS. The navigation bar on my site appears to be functioning properly at first glance, but upon hovering over it, empty bars highlight as if they are clickable, which is quite frustrating. Any insights into why this issue may have arisen?

You can visually see the problem here

Despite following an old tutorial video from a dormant YouTube channel, I am clueless about what could be causing this discrepancy. Since there has been no recent activity on the channel, I decided to seek help here instead.

Here is the CSS code for the navigation bar:

body {
    margin:0;
    padding:0;
    background:#ccc;
}

.nav ul {
    background-color:#344629;
    text-align:center;
    padding:0;
    margin:0;
}

.nav li {
    display: inline-block;
}

.nav a {
    text-decoration:none;
    color:white;
    width:100px;
    display:inline-block;
    padding:10px 10px 10px 0px;
    font-size:17px;
    font-family:Helvetica;
}

.nav a:hover {
    background:#5e9342;
    transition: 0.4s;
}

And here is the HTML code:

<!DOCTYPE html>

<html lang ="en">
<head>
    <meta charset="UTF-8">
    <title>Welcome To Lanarkshire</title>

    <link rel="stylesheet" type="text/css" href="css/styles.css">

</head>

<body>
<div class="nav">
    <ul>
        <li><a href="#">Home</li>
        <li><a href="#">Gallery</li>
        <li><a href="#">Attractions</li>
        <li><a href="#">Food & Drink</li>
        <li><a href="#">Contact Us</li>
    </ul>
</div>

</html>

I am aiming for only the text boxes in the navigation bar to be highlighted and clickable, nothing else.

Answer №1

To solve your problem, make sure to close your anchor tags properly. Flavio's comment had the correct suggestion...

For example:

<ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">Gallery</a></li>
    <li><a href="#">Attractions</a></li>
    <li><a href="#">Food & Drink</a></li>
    <li><a href="#">Contact Us</a></li>
</ul>

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 there a way to insert a record upon the user clicking on the Add Record button?

// Here is my Component code // I want to figure out how to add a new row to the table with fresh values. import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-uom', templateUrl: './uom.component.html ...

Fancybox navigation link section

I'm currently in the process of creating a photo gallery website with fancybox. As it stands, the navigation for moving to the next/previous image is tied to the position of the arrow icons. Clicking anywhere from the middle of each image to the y-axi ...

Issue with Angular FormControl Pattern Validator failing to validate against regex pattern

My goal is to restrict a text input field to specific characters only. I am looking to allow: alphanumeric characters (a-z A-Z 0-9) 3 special characters (comma, dash, single quotation mark) : , - ' A few accented characters: à â ç è é ê î ô ...

Discover the method for retrieving the value of a toggle-style checkbox

I am currently working with a toggle switch checkbox and I need to extract its value using JavaScript or jQuery when the state changes. Based on this value, I aim to highlight the text of the label associated with the toggle switch, whether it's opti ...

Issue with jQuery clone(): original content's radio button toggling display function not functioning as intended

I'm duplicating HTML code using jQuery and adding it to a div. However, after appending the original content, both radio buttons become unchecked. How can I resolve this issue? Can anyone assist me with this? jsfiddle HTML <div class="conten ...

Tips for generating a dynamic table in Javascript from a JSON object containing nested lists

I'm currently working on converting a JSON file into an HTML table, where the values may contain nested lists. For instance: { "entry 1":[ ["text1", "text2", "text3"], ["text4", ...

Display the element only when the request sent with getJSON exceeds a certain threshold of time in milliseconds

Here's a snippet of my JavaScript code: surveyBusy.show(); $.getJSON(apiUrl + '/' + id) .done(function (data) { ... surveyBusy.hide(); }) .fail(function (jqXHR, textStatus, err) { ... surveyBusy. ...

What is the best method for automatically closing the modal window?

I implemented a modal window on my website. Within the modal, there is a green button labeled "Visit" which triggers the "Bootstrap Tour". I aim for the modal to automatically close when the tour starts. To access this feature on my site, users need to ...

Is there a way to customize the hover effect on this navigation link in Bootstrap that includes a span and an icon from Bootstrap?

<li class="nav-item mt-3"> <a href="#" class="nav-link px-2 d-flex justify-content-start align-items-center"> <i class="nav-icon bi bi-calculator-fill fs-4"></i> ...

Is it possible to accomplish this straightforward task using PHP?

Essentially, my goal is to have the content inside the h1 tag duplicated in the h2 tag as well. Take a look at the example provided below. <!DOCTYPE html> <html> <body> <h1>The content here should also appear in the H2 tag.</h1 ...

Using JQuery to apply a CSS class to a designated webpage

In an effort to achieve a responsive design, I am seeking to add an active class to an unordered list item based on the specific page that the user is viewing. Essentially, I want to implement conditional formatting using jQuery while learning on MAMP. Cu ...

Error: The symbol $ is not recognized

This is a snippet of code that I've written to automate address filling and extract latitude/longitude/address information. <html> <head> <LINK rel="stylesheet" type="text/css" href="style.css"> <script type="text/javascript" sr ...

Invoking a Directive within another Directive

Feel free to check out this demo on Plunkr. I've set up a basic structure: <body ng-app="myApp"> <div ng-controller="myController"> <parent-directive></parent-directive> <child-directive></child-direc ...

CSS based on conditions for 2 specific divs

Hello, I am working on an HTML page where I need to apply CSS only if certain conditions are met. The div with the id "flipbook-page3-front" will always be present on this HTML page. Sometimes, another div with the id "pagesFlipbook" may also appear on t ...

Creating a clickable button that will trigger a function when pressed, continuously running the function until the button is released

I am currently working on a project where I am trying to make an object move using an HTML button. However, the function is only executed once with a single click, whereas I want it to execute continuously as long as the button is pressed down. Below is ...

JavaScript logic for playing the hangman game

I am working on creating a hangman game and I need some guidance on developing the logic. I am new to programming, so I would like to keep it simple by using basic syntax. One thing I'm trying to figure out is how to display dashes (-) that represent ...

Adjustable widths

Why are my three divs not lining up properly when I try to make them take up a third of the width each (33%)? They seem to jump around and get misaligned when I resize the window. What am I missing? HTML <div class="step"> <i class="fa fa-user ...

Having trouble with fixing the width and aligning a custom scrollbar in the center

I have been working on creating a carousel with items that are horizontally aligned. With the requirement of having each child element (approximately a dozen) to fill one third of the parent's width and displaying three items at once, I utilized Boot ...

What is the best way to eliminate unexplained spacing at the bottom of a webpage using CSS?

I am struggling to create a basic webpage using Bootstrap and D3, and I can't seem to figure out how to remove the excess whitespace at the bottom. Any tips on how to resolve this issue would be greatly appreciated. I attempted to set the min-height ...

Accessing PHP variables within the HTML portion of a PHP document

Setting up my own contact form for the first time using PHP has been a learning experience. While I am able to receive emails from the form, I'm struggling to display the user-inputted information in the email. The HTML <label for="name"> ...