Beside the element, a dropdown navigation menu emerges

Trying to work on a dropdown menu here. It appears to be functioning, but there's a small issue - the dropdown shows up on the right side of the element instead of directly below it. I have a feeling it has to do with either position or padding, but I haven't been able to pinpoint the exact cause. Appreciate any help on this as I'm still learning CSS and every bit of guidance counts!

HTML

    <nav id="navigatie" class="nav">
    <ul>
        <li><a class="active" href="index.html">Home</a>
        <li><a href="html/producten.html">Producten</a></li>
        <li><a href="html/personaliseren.html">Personaliseren</a></li>
        <li><a>Over ons</a>
            <ul>
                <li><a href="html/blog.html">Blog</a></li>
                <li><a href="html/contact.html">Contact</a></li>
                <li><a href="html/faq.html">FAQ</a></li>
            </ul>
        </li>
    </ul>
</nav>

CSS

html {
    background: #936A4A;
}

nav {
    position: absolute;
    width: 100%;
    top: 0;
    left: 0;
    background: #F5F5F5;

}

ul {
    display: flex;
    flex-wrap: wrap;
    padding: 0;
}

ul li {
    width: 25%;
}

ul li > ul {
    display: none;
    flex-direction: column;
}

ul li:hover > ul {
    display: flex;
    flex-wrap: wrap;
}

ul li > ul li {
    width: 100%;
    height: 100%;
}

li {
    display: flex;
    flex: auto;

}

li a {
    color: #B85750;
    text-decoration: none;
}

.active {
    pointer-events: none
}

Answer №1

Absolutely, the submenu should be positioned in relation to the parent li.

html {
  background: #936A4A;
}

nav {
  position: absolute;
  width: 100%;
  top: 0;
  left: 0;
  background: #F5F5F5;
}

ul {
  display: flex;
  flex-wrap: wrap;
  padding: 0;
}

ul li {
  width: 25%;
  position: relative;
}

ul li>ul {
  position: absolute;
  left: 0;
  top: 100%;
  width: 100%;
  background: lightblue;
  /* display: none; */
  flex-direction: column;
}

ul li:hover>ul {
  display: flex;
  flex-wrap: wrap;
}

ul li>ul li {
  width: 100%;
}

li {
  display: flex;
  flex: auto;
}

li a {
  color: #B85750;
  text-decoration: none;
}

.active {
  pointer-events: none
}
<nav id="navigatie" class="nav">
  <ul>
    <li><a class="active" href="index.html">Home</a>
      <li><a href="html/producten.html">Producten</a></li>
      <li><a href="html/personaliseren.html">Personaliseren</a></li>
      <li><a>Over ons</a>
        <ul>
          <li><a href="html/blog.html">Blog</a></li>
          <li><a href="html/contact.html">Contact</a></li>
          <li><a href="html/faq.html">FAQ</a></li>
        </ul>
      </li>
  </ul>
</nav>

Answer №2

Kindly review the solution provided below.

html {
          background: #fff;
        }
            
        .parent-container{
            position: relative;
            width:100%;
            height: 100%;
        }
            
        nav {
            background: #F5F5F5;
        }


        ul { 
            list-style: none;
            margin: 0;
            padding-left: 0;
        }

        li {
            background: #936A4A; 
            display: block;
            float: left;
            padding: 1rem;
            position: relative;
            text-decoration: none;
            transition-duration: 0.5s;
        }

        li a {
          color: #fff;
        }

        li:hover {    
            cursor: pointer;
        }

        ul li ul {    
          visibility: hidden;
          opacity: 0;
          min-width: 5rem;
          position: absolute;
          transition: all 0.5s ease;
          margin-top: 1rem;
          left: 0;
          display: none;
          background: lightblue;
        }

        ul li:hover > ul,
        ul li ul:hover {
          visibility: visible;
          opacity: 1;
          display: block;
        }

        ul li ul li {
          clear: both;
          width: 100%;
        }
<!DOCTYPE html>
<html>
    <head>        
        <link href="app.css" rel="stylesheet" type="text/css"/>
    </head>
<body>
    <div class="parent-container">
        <nav role="navigation" class="nav" id="navigatie">
          <ul>
            <li><a class="active" href="index.html">Home</a>
            <li><a href="html/producten.html">Producten</a></li>
            <li><a href="html/personaliseren.html">Personaliseren</a></li>
            <li><a href="#">Over ons</a>
              <ul class="dropdown">
                <li><a href="html/blog.html">Blog</a></li>
                <li><a href="html/contact.html">Contact</a></li>
                <li><a href="html/faq.html">FAQ</a>/<li>
              </ul>
            </li>   
          </ul>
        </nav>
    </div>   
</body>
</html>

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

Bootstrap 5 - Achieve automatic column width within a row

In my Bootstrap 5 setup, I have a variety of pages that have different column layouts - sometimes 2 columns, sometimes 3. The template system I'm using dynamically adjusts the layout to accommodate the need for a third column when necessary. <div ...

Selecting properties from a GeoJSON object on the fly with Leaflet

I am currently attempting to dynamically modify the displayed property on my leaflet map. Below is the code I have been working with: $("#button_thermal").click(function(){ $.getJSON("physicalProperties.geojson", function(data) { var geojson2 = L.geoJson( ...

The slider thumb is not showing up properly on Microsoft Edge

Hey there! I'm experiencing an issue with the range slider's thumb display in Microsoft Edge. It appears to be positioned inside the track rather than outside as intended. Take a look at this snapshot for clarification: https://i.stack.imgur.co ...

Updating the background of a div in HTML through the power of JavaScript

I am having trouble changing the background of a DIV. I believe my code is correct, but it doesn't seem to be working. I suspect the error lies with the URL parameter, as the function works without it. Here is my code: <script language="JavaS ...

Understanding the res.render method in JavaScript can be a bit tricky at first

In my spare time, I have been immersing myself in coding lessons and have encountered some puzzling aspects of the code: Firstly, there is a confusion surrounding the action attribute in HTML Secondly, this particular piece of code is causing me some b ...

Why is my second CSS animation, which is running late, causing such chaos?

I am currently in the process of animating a simple text. However, I am encountering some issues with making it disappear after a certain period of time: During the initial fade in, the opacity value does not seem to be respected, as the text seems to a ...

Click on the link or tab to update the marker location on the Google Map

Can you click on Tab 2 to change the marker/location, and then go back to Tab 1 to switch it back to the original location? [Links to Fiddle] http://jsfiddle.net/ye3x8/ function initialize() { var styles = [{ stylers: [{ saturati ...

Struggling to achieve success in redirecting with passport for Facebook

For a "todolist" web application that utilizes passport-facebook for third party authentication, the following code is implemented: passport.use(new FacebookStrategy({ clientID: '566950043453498', clientSecret: '555022a61da40afc8ead59 ...

How to modify the background color within the mat-menu-panel

Incorporating angular 9 and less into my current project, I have encountered an issue with a mat-menu-panel where my mat-menu-item is located. While I have successfully changed the color of my mat-menu-item, I am now faced with the challenge of changing th ...

Fade out the content using jQuery and simultaneously change the div

I stumbled upon this interesting code snippet here: http://jsfiddle.net/7hqyq/ Being a novice in the realm of jQuery, I am curious to learn how one can modify the background color of the selected square (including the first square on page load) and implem ...

What is the best way to line up a checkbox and its labels alongside a dropdown menu?

My index.html file has a header like this: https://i.sstatic.net/s0hAt.png I'm trying to align the checkbox and its label with the dropdown menu "In ordine". I'm using only bootstrap (no custom classes) and my current page layout is as follows. ...

Dynamically insert a new row into an HTML table using AJAX and refresh the table with .load method

I am facing an issue with my HTML table that loads data dynamically through a PHP snippet containing SQL queries. There is a Select option and a button on the table to add a new row, which triggers an AJAX procedure to send the data to PHP for insertion in ...

Ionic Framework: Eliminating the tiny 1px vertical scroll glitch for single-line content

Is anyone else experiencing this issue? I noticed that my page content is not filling up the entire space, even though it's just one line of text. There seems to be a 1px vertical scroll present, and the same problem occurs with the content in the sid ...

Having trouble getting the Bootstrap toggle checkbox to function properly within Angular 2 components?

Working on an Angular 2 project with Bootstrap, I recently tried to integrate a bootstrap-toggle checkbox into the UI. Despite following the instructions from this site, the checkbox was displayed as a normal checkbox instead of toggled. The Index.html cod ...

Prevent the Icon in Material UI from simultaneously changing

I'm working on a table where clicking one icon changes all icons in the list to a different icon. However, I want to prevent them from changing simultaneously. Any suggestions on how to tackle this issue? Code: import React from 'react'; im ...

How can I override the maximum body width to enable specific div elements to extend beyond that limit?

While I've come across similar questions to mine, none of them seem to solve my specific issue. Essentially, I've set the body width to 960px, which is a common standard practice. However, there are certain elements such as header, footer, and so ...

What are the steps for rearranging a table column?

I am trying to show a text file in a table and allocate some code to each entry. I can display the text file. I can assign the code for each record (though this part is still under development). However, I have encountered an issue. The columns of the t ...

What is the best way to position my Jchartfx area graph below my gridview?

When my page loads, the graph appears like this. It consistently shows up in the top left corner even though it should be positioned underneath the grid view as intended. var chart1; function createGraph(mpy) { if (mpy == undefined) mpy = 12.00; ch ...

Creating an array using Vue.js

When I initialize a Vue data array like this [0: Object, 2: Object];, the console log in Vue shows the array as [0: Object, 1: undefined 2: Object];. This causes issues when iterating through with 'v-for="cell in row.cells"' as it results in tryi ...

Progressing through the Material UI LinearProgress bar in steps

How can I split a progress bar into more steps to achieve a design like this? https://i.stack.imgur.com/lRMj6.png I attempted using this code but couldn't find an option for splitting: <LinearProgress variant="determinate" classes={{ ...