Spacing between the main menu items and the sub-menu items

Struggling to get this dropdown menu functioning properly. Seeking ways to increase spacing between the menus through padding and the ::after selector.

HTML:

<div id="menu">
    <div id="wrapper">
        <ul class="navbar">
            <li><a href="#">Menu</a>
              <ul>
                <li><a href="#">Hej 1</a></li>
                <li><a href="#">Hej 2</a></li>
                <li><a href="#">Hej 3</a></li>
             </ul>         
            </li> 
        </ul>
    </div>
</div>

CSS:

body {
    background-color: #efefef;
}

#menu{
    height:auto;
    position: absolute;
    margin: 0px;
}

#wrapper{
    position:absolute;
    top: 0px;
    left:0px;
    height: auto;
    margin: 0px;

}

#wrapper ul{
    margin:0px;
    padding: 0px;
    height: auto;
    width: auto;
    background-color: #fff;
    border-radius: 8px;    
}

#wrapper ul li,#wrapper ul li a, #wrapper ul li ul li, #wrapper li ul li a{
    position: relative;
    list-style: none;
    display: inline-block;
    font-size: 14px;
    font-family: sans-serif;
    text-decoration: none;
    color: #808285;
    padding: 3px 10px 3px 10px;
    transition: all 0.3s ease 0s;
}

#wrapper ul li ul{
    display: none;
    position: absolute;
    top: 20px;
    margin-top: 20px;
    right: -30px;
    width: 150px;
    background-color: #FFFFFF;
    border-radius: 0px;
    transition: all 0.3s ease 0s;
    border-radius: 8px;
    left: 5px;
}

#wrapper ul li ul li{
    position: relative;
    top: auto;
    left: 0px;
    height: auto;
    width: 150px;
    list-style: none;
    display: list-item;
    padding: 3px 5px 3px 5px;
    margin-top: 5px;
}

#wrapper ul li a:hover, #wrapper ul li ul li a:hover{
    color: #ba141a;
}

#wrapper ul li:hover ul{
    display: block;
}

#wrapper ul li ul li:hover{ 
    width: 132px;
}

See it in action: http://jsfiddle.net/yMvg9/1/

Can anyone identify the issue here?

Answer №1

decrease the margin of #wrapper ul li ul

#wrapper ul li ul {
   margin-top: 6px;
}

view the demo

Answer №2

Try removing or reducing the margin:20px within the #wrapper ul li ul to resolve the issue

#wrapper ul li ul{
display: none;
position: absolute;
top: 20px;
margin-top: 20px;
right: -30px;
width: 150px;
background-color: #FFFFFF;
border-radius: 0px;
transition: all 0.3s ease 0s;
border-radius: 8px;
left: 5px;
}

Could be updated to something like

#wrapper ul li ul{
display: none;
position: absolute;
top: 20px;
margin-top:0px; /* alternatively, adjust as needed */
right: -30px;
width: 150px;
background-color: #FFFFFF;
border-radius: 0px;
transition: all 0.3s ease 0s;
border-radius: 8px;
left: 5px;
}

Answer №4

You currently have a top margin of 20px applied to { #wrapper ul li ul }

#wrapper ul li ul{
display: none;
position: absolute;
top: 20px;
margin-top: 20px; // Consider removing or reducing this...
right: -30px;
width: 150px;
background-color: #FFFFFF;
border-radius: 8px;
transition: all 0.3s ease 0s;
left: 5px;
}

Implementing these changes should help resolve the issue...

View working example on Fiddle

Answer №5

Copy and paste the following CSS into your style sheet

#container ul li ul{ 
     background: none;
}

#container ul li ul li{
     background-color: #FFFFFF;
}

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

The ckeditor vanishes upon refreshing the div element

I have created two pages named openclosediv.php and content.php. The openclosediv.php page contains a list of records and a button that can show/hide the div, bringing in the content from content.php. However, I am facing an issue where the CKEditor in the ...

Internet Explorer does not show SVG HTML links, while they are visible on Chrome and Firefox

Presently, I have a graph being displayed with text and links located beneath the graph. The entirety of the code is crafted in SVG format. Below you will find my text code, followed by my html code. The text renders properly on all tested browsers (includ ...

When combining li, radio-input, and label, there is no padding at the top

I am facing an issue with the padding at the top of my list items. Here is a link to a working Fiddle: [http://jsfiddle.net/TH3zq/9/][1] http://jsfiddle.net/TH3zq/9/ Can anyone suggest a CSS style solution for this problem? Thanks, John ...

Undefined variable 'site' error encountered in Codeigniter views

Query: I encountered an issue while running the program: undefined variable "site" in the views. The code snippet is as follows: <ul class="nav nav-pills"> <li><a href="<?php echo $site ?>/CI_timeline/index"& ...

Show a random number within a Bootstrap tooltip

I am trying to make a bootstrap popover display a random number every time it is clicked, but my current implementation is only showing the initial number generated and does not update on subsequent clicks. Below is my code snippet: <button type=&qu ...

placing a vertical bootstrap button along the left border

My goal is to place a vertical bootstrap button on the left side of the screen. Currently, I have implemented the following CSS: #button1 { position: absolute !important; z-index: 10 !important; left: 0px !important; bottom: 20% !important; tr ...

Create a jQuery animation that mimics the Safari home page experience. Create a

Is there a way to achieve a similar effect as Safari's new tab using HTML5 canvas instead of CSS3 3d transform? While we can create a similar transformation with CSS3 3D transform, it is limited to Webkit browsers. Can we use CANVAS to replicate this ...

creating nested columns within a parent column using flexbox techniques

Struggling with column height issues in Bootstrap 3? Consider using flexboxes for a simpler solution. Check out the design image I created using Bootstrap 3: https://i.sstatic.net/PVCKm.png Can this design be replicated with flexboxes? I have successfull ...

Slideshow plugin glitch on Safari and Opera caused by jQuery implementation

My current project involves utilizing a fantastic plugin called Sequence.js for creating animations and transitions with CSS3 based on jQuery. I have set up a simple responsive fadeIn-fadeOut slideshow using this plugin. While everything works smoothly an ...

Tips for executing a function on a specific class selector using the document.getElementsByClassName method

When I click on a specific class, I want to implement a fade-out function in JavaScript. However, I am struggling to make a particular class fade out successfully. I attempted to use the this keyword, but it seems like I might be using it incorrectly bec ...

Space allocation among the columns' borders

My layout consists of 3 columns in a row, each with the class col-xs-4, covering the entire row. I am trying to add a border to each column without them overlapping. Currently, I have applied the border but there is no spacing between the columns. I want ...

Ensure that the radio button and its corresponding label are aligned on the same horizontal line

When dealing with multiple radio buttons, each paired with a label, how can you ensure that the button and label always stay on the same line, while also automatically shifting to the next line for the next pair? For example, on a large screen: () Label ...

Troubleshooting an issue with IE regarding box-shadow CSS functionality

I have a problem with my website design where the box-shadow effect on the top menu is not displaying properly in Internet Explorer. I tried adding specific code for IE8 and lower versions to fix this issue: zoom:1; /* This enables hasLayout, which is nec ...

The CSS grid header is malfunctioning on Chrome and Opera, while functioning correctly on Firefox

My first attempt at creating a website layout using grid was successful in Firefox, but not in Chrome and Opera. The header is taking up only about 1/3 of the width, leaving the rest empty on these browsers. However, everything else, including the mobile l ...

Using the Bootstrap grid system beyond the boundaries of the div container

Struggling to place 2 input elements inside a bootstrap grid, I noticed they are positioned outside the div container, either to the left or right side. Despite my attempts, the code seems fine: <div style="max-width:500px;margin:auto;"> <di ...

When implementing Critical CSS, the Jquery function fails to execute upon loading

Currently, I am working on optimizing my website at . In an attempt to improve its performance, I decided to implement critical CSS using penthouse. The Critical CSS code can be found here, generously provided by the main developer of penthouse. However, ...

Miscalculation in PHP MySQL: Incorrect output when adding field 1 and multiplying field 2 by

In my MySQL table, there are 4 fields: product price cost, selling price, stock of products, and earnings per unit. For example: If the cost of our product is $100, we sell it for $120, and we have a stock of 10 units, the following code calculates the e ...

Tips for applying unique CSS classes to individual templates in Joomla

I manage a website at www.kadamjay.kg using an RT template system where each language version has its own unique template. However, when I add a class to a specific element, it only changes on one template and there are no additional templates in the pat ...

Using Spring Boot RestController to Serve HTML Pages

I'm having trouble accessing the HTML page I created. Here is an overview of my project: https://i.sstatic.net/Wvmus.png This is the "IndexController" class: @RestController @AllArgsConstructor @RequestMapping(path = "/webpage") public class IndexCo ...

Tips for transferring input values from a JavaScript function to a separate PHP page for storage in a database

This code snippet allows dynamic rows to be added to a table when the add button is clicked. Now, the goal is to retrieve the values entered into the text boxes and submit them to the database. <div id="addinput"> <p> <button name=" ...