Is it possible that CSS is causing the links to be unclickable?

I'm experiencing an issue where the links in my navigation bar are unclickable unless I remove some of the CSS styling I added.

Here is the specific CSS snippet that needs to be removed for the links to work:

.main-nav {
  float: right;
  list-style: none;
  margin-top: 30px;
}

The problem seems to be related to the float: right; property, as disabling it makes the links clickable again.

{
  margin: 0;
  padding: 0;
}

header {
  background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url(zomb2.PNG);
  height: 100vh;
  background-size: cover;
  background-position: center;
}

.main-nav {
  float: right;
  list-style: none;
  margin-top: 30px;
}

<main-nav li {
  display: inline-block;
}

.main-nav li a {
  color: white;
  text-decoration: none;
  
...
... (Additional CSS code removed for brevity) 

    </div>

  </div>

Thank you in advance for any assistance! I believe it's something simple that I'm overlooking, but after searching around extensively, I couldn't find a solution specifically addressing this issue. Any help would be greatly appreciated!

Answer №1

.hero when using position:absolute will overlap the header, to bring your links on top of it, use

position:/* any value but static */
+ z-index

a {
  position:relative;
  z-index:1;
}

See the demo below:

{
  margin: 0;
  padding: 0;
}

header {
  background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url(zomb2.PNG);
  height: 100vh;
  background-size: cover;
  background-position: center;
}

.main-nav {
  float: right;
  list-style: none;
  margin-top: 30px;
}

.main-nav li {
  display: inline-block;
}

.main-nav li a {
  color: white;
  text-decoration: none;
  padding: 5px 20px;
  font-family: "Roboto", sans-serif;
  font-weight: bold;
  position:relative;
  z-index:1;
}

.main-nav li.active {
  border: 1px solid white;
}

.main-nav li a:hover {
  border: 1px solid white;
}

.logo {
  width: 150px;
  height: auto;
  float: left;
  color: white;
  font-size: 20px;
}

body {
  font-family: monospace;
}

.row {
  max-width: 1200px;
  margin: auto;
}

.hero {
  position: absolute;
  width: 1200px;
  margin-left: 0px;
  margin-top: 0px;
}

h1 {
  color: white;
  text-transform: uppercase;
  font-size: 70px;
  text-align: center;
  margin-top: 275px;
}

h2 {
  color: white;
  text-transform: uppercase;
  font-size: 35px;
  text-align: center;
}

.button {
  margin-top: 30px;
  margin-left: 440px;
}

.btn {
  border: 1px solid white;
  padding: 10px 30px;
  color: white;
  text-decoration: none;
  margin-right: 5px;
  font-size: 13px;
  text-transform: uppercase;
}

.btn-one {
  background-color: darkorange;
  font-family: "Roboto", sans-serif;
}

.btn-two {
  background-color: darkorange;
  font-family: "Roboto", sans-serif;
}

.btn-two: hover {
  background-color: darkorange;
}
<header>
  <div class="row">
    <div class="logo">
    </div>

    <ul class="main-nav">
      <li class="active"><a href="">Home</a></li>
      <li><a href="about.html">Learn More</a></li>
      <li><a href="zombies.html">Real Zombies</a></li>
      <li><a href="ordinance.html">Guns and Ammo</a></li>
      <li><a href="news.html">The Latest</a></li>
      <li><a href="faq.html">FAQ</a></li>
    </ul>
  </div>

  <div class="hero">
    <h1> Real Zombie Vs. Human Battles </h1>
    <h2> Choose your side..</h2>
    <div class="button">
      <a href="" class="btn btn-one">Zombies</a>
      <a href="" class="btn btn-two">Humans</a>
    </div>
  </div>

Answer №2

Consider updating your CSS as follows:

.main-nav
{
     float: right;
     list-style: none;
     margin-top: 30px;
     position: relative;
     z-index: 10;
}
Setting the z-index property should resolve the issue. However, it is important to note that this will only work if the position property is also set to relative.

For more detailed information, you can visit this link: https://developer.mozilla.org/en-US/docs/Web/CSS/z-index

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

When using $.post along with serialize, the post variables and values fail to be sent

I am trying to use jQuery to post data to process.php and then display everything that occurs in the processing file. Currently, I have successfully loaded the file using ajax. For example, when I type echo "Hello world!"; it returns Hello world! Howeve ...

Arranging form elements and a map in a side-by-side layout using HTML5

How can I align the contents of a map and a form side by side with responsive design? I've attempted using tables and lists, but the form keeps appearing on top of the map. Ideally, I want the contents to be displayed side by side on wider screens and ...

Create a dynamic feature in Bootstrap4 where the navigation bar changes color as the user scrolls to different sections of the

Currently building my personal portfolio website with Bootstrap 4, I came up with a great idea: changing the navigation bar color based on different sections of the website. I attempted to achieve this using JQuery's offset and scrollTop functions, bu ...

css: Aligning fonts horizontally when they have varying sizes

First time asking a question on this platform! I'm attempting to achieve a "pixel perfect" horizontal alignment of two lines of text, with each line having a different font size. <style type="text/css"> * { font-family: sans-serif;} ...

Discovering the pressed submit button in Node.js: A beginner's guide

How can the controller or admin determine which submit button was pressed in a form like this? <form method="POST"> <input type="submit" value="Add Admin" name="addAdmin"> <input t ...

As the screen size decreases, stacked Font Awesome icons seem to vanish

Currently, I'm designing a form that requires the user to select a color scheme by clicking on circle font awesome icons. These icons are implemented using Bootstrap and when clicked, a stacked font-awesome icon appears. However, I've encountered ...

Locate integer and add a decimal point followed by two zeros

I want to add .00 to a number if it is not already a decimal. However, the code I am using below seems to be converting the entire number to 0.00 instead of just appending .00 at the end. For instance, if the number is 12,200, it ends up as 0.00 after appl ...

Angular Markdown Styling: A Guide

Currently, I am using Angular and Scully. I would like to add style to the image in a markdown file within Angular, but I am unsure of how to accomplish this task. The image is currently displaying too large. Can anyone provide me with useful advice on how ...

Error: The Android Phonegap framework encountered an issue when trying to access the getDuration function without a properly initialized media

Encountering a LogCat error that I need assistance with. The web app code functions properly on iOS, but presents an error message on Android. Unable to call getDuration as mediaplayer is invalid Your help is greatly appreciated. ...

Tips for effectively utilizing the display:none property to conceal elements and permanently eliminate them from the DOM

While working on my website, I utilized CSS media queries to hide certain elements by using display: none. Even though this effectively hides the element from view, it still lingers in the DOM. Is there a way to completely eliminate the element from the ...

The map and its multiple markers are not showing up

I am attempting to display multiple markers on a Google map. Everything is working fine in two scenarios: When I display ONE marker When I write the GPS coordinates of different markers I have a database that contains longitude and latitude values. I wan ...

Entering text into a field / Inserting data into a MySQL database / Presenting

I am facing a challenge that I'm uncertain how to resolve. The issue lies with a textarea on my form that permits the user to input data in the following format: Windows XP Home and Professional<br />(32 and 64 bit) Windows 7 Home and Professi ...

Import of Bootstrap causing disruption in positioning of <figure> element

Check out this codepen example: https://codepen.io/anon/pen/Xgqjyq h2 { color: #111; font-family: 'Open Sans', sans-serif; font-size: 20px; font-weight: bold; text-align: center; } .content { margin-left: 5px; margin-right: 5px; t ...

Automatically scroll a div when the internal div is in focus

I want to create a scrollable div that allows for scrolling even when the mouse is over the content inside the div, not just on the blank areas beside it. Here is the code I am currently using: var main = document.getElementById('main-site'); va ...

What significance do the blank quotes hold in terms of value?

Is it possible to enter multiple values for the "favoriteCities" field since the value is empty? <input name="favoriteCities[]" value=""/> ...

Achieving vertical centering in Bootstrap using the "table-cell" method

I'm trying to center a div both vertically and horizontally using the "table-cell" method without specifying a specific height. However, it's not working as expected. Why isn't this method working for me? Here is the code I am using: < ...

Ways to create a menu that appears as fixed-top without moving along with the scroll

When I use the fixed-top class on my nav bar, it stays on top of the header as shown in the image. However, when I scroll down, the menu also scrolls down. Is there a way to make the navigation look the same but not follow when scrolling? I want to achieve ...

Animate an image to the right when clicked, then return it to the left with a second click

Seeking help with animating a set of images to move individually 300px right on first click, and then 300px left when clicked again. I'm currently facing an issue where my code is not working. It could be due to A) syntax errors or B) the images not ...

Calculate the quantity of rows within a specific div container

Looking at the image provided, there are multiple divs inside a main div. I am trying to figure out how many rows the main div contains. For instance, in this particular scenario, there are 5 rows. It is important to mention that the inner div is floated ...

What can I do to prevent my background images from overlapping each other?

I'm trying to get the background images to display side by side with equal sizes and no spacing between them. The current code achieves this, but the images end up overlapping slightly, not filling 100% of the container. Despite setting the backgroun ...