Children within a list are creating spaces between the main unordered list

I am working on a navigation bar with submenus.

I would like the submenu ul to be 139px wide (so when hovered over, the dropdown box will expand to 139px). However, setting this width also results in a gap between the parent links.

For illustration:

In the following illustration, the spacing between the links appears fine initially. Nonetheless, when hovering over the products link, a gap appears between products and blog.

It's acceptable for the submenu to overlap with the blog li. Currently, the goal is to eliminate the gap.

.main_menu>div ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: row;
}

.main_menu>div ul li {
  display: inline-block;
  vertical-align: middle;
  line-height: 1em;
  padding: 1.2em 0.9em;
  font-weight: 500;
  color: #333;
  border-radius: 25%;
  cursor: pointer;
}


/* showing dropdown on parent hover */

.item-has-children .menu-children-wrapper {
  border: 1px solid red;
  height: auto;
  background-color: #fff;
  flex-direction: column!important;
  display: none;
}

.item-has-children:hover ul {
  display: block;
  width: 139px;
}
<div class="main_menu">
  <div class="menu_container">
    <ul>
      <li class="item-has-children"><a href="#">Products ▾</a>
        <ul class="menu-children-wrapper">
          <li class="menu-item"><a href="#">Link 1</a></li>
          <li class="menu-item"><a href="#">Link 2</a></li>
          <li class="menu-item"><a href="#">Link 3</a></li>
        </ul>
      </li>
      <li class="menu-item"><a href="#">Blog</a></li>
    </ul>
  </div>
</div>

Answer №1

To ensure the dropdown menu appears correctly, make sure to include the "position: absolute;" property within the CSS styling for the ul element. Hopefully, this solution resolves your issue.

.main_menu>div ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: row;
}

.main_menu>div ul li {
  display: inline-block;
  vertical-align: middle;
  line-height: 1em;
  padding: 1.2em 0.9em;
  font-weight: 500;
  color: #333;
  border-radius: 25%;
  cursor: pointer;
}


/* showing dropdown on parent hover */

.item-has-children .menu-children-wrapper {
  border: 1px solid red;
  height: auto;
  background-color: #fff;
  flex-direction: column!important;
  display: none;
}

.item-has-children:hover ul {
  display: block;
  width: 139px;
  position:absolute;
}
<div class="main_menu">
  <div class="menu_container">
    <ul>
      <li class="item-has-children"><a href="#">Products ▾</a>
        <ul class="menu-children-wrapper">
          <li class="menu-item"><a href="#">Link 1</a></li>
          <li class="menu-item"><a href="#">Link 2</a></li>
          <li class="menu-item"><a href="#">Link 3</a></li>
        </ul>
      </li>
      <li class="menu-item"><a href="#">Blog</a></li>
    </ul>
  </div>
</div>

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

Scrolling the Html5 canvas smoothly without the need for constant re-rendering

Is it feasible to achieve smooth panning on an HTML5 canvas without the need for rerendering? Are there any examples of code that demonstrate this functionality? Furthermore, is it also possible to apply the same technique for zooming? I am experiencing ...

Tips for centering text in a dijitTextBox:

Ensure that the text is centered vertically with left padding and placeholder text included Check out the image link below: https://i.stack.imgur.com/PbHDa.jpg Snippet of my xPage code: <xe:djTextBox id="djTextBoxSearch" style="width:100%;height: ...

What is the best way to send an HTML report through email with embedded images as an attachment?

Currently, I am in the process of generating a report using ExtentReports that will be distributed via email to team members who are outside of our domain. To capture screenshots of any test failures, I utilize a screenshot method which saves these images ...

Incorporate a website design template into your Visual Studio project

I have a website application that I created but it's currently empty. I would like to add some style to it using online free website templates that I downloaded. However, I'm unsure of how to incorporate the css, font, and images folders into the ...

Tips for correctly positioning CSS elements:

I am currently working on a slider using noUi Slider and aiming for an elegant solution. To accommodate the large size of the handle, I expanded the base UI with extra values which are not allowed, causing the handle to jump back to the permitted values. T ...

How to position a textarea alongside a checkbox using CSS with Bootstrap

I'm having an issue aligning a text area next to a checkbox in my Bootstrap HTML. Here's the code snippet: <div class="form-group row"> <div class="col-12 form-check"> <label class="col-3 col-form-label" for="check15"& ...

When a radio button is clicked in Angular7 and it shares the same form control name, both radio buttons are being

Visit this StackBlitz link for more information. places = ['effil tower','new discover'] new FormGroup({place: new FormControl()}); <div *ngIf="places?.length > 0" class="col-12"> <div style=" padding-top: 1e ...

Transform an html content into a Java statement using "out.println" function

Is there a way to transform an HTML string into a Java "out.println" statement using Java? For example: <h1>Hello world</h1><p style="background-color:red">hello</p> can be converted to out.println("<h1>Hello world</h1& ...

Getting Values from .Properties File in JavaScript/HTML pages that are Executing in a Node.js Server

I have a configuration file named "site.properties" with the following content: #Properties file #Database Connection Info db.host.name = localhost db.user.name = username db.password = password db.database.schema = db1 #Server Connection Info ...

Incorporating a header include on every page throughout my website

Is there a way to include headers and footers in your HTML web pages without having to duplicate code on every page? I understand that this can be done using PHP, but what if you are creating a website solely with HTML? If there is no solution to avoid r ...

What causes the scrollbar to not extend to the bottom when connected to another scrollbar via a JavaScript equation?

I have been working on a code that involves multiple scrollbars that are all linked together. When you move one scrollbar, the other two will move proportionally. However, due to differences in width, the scroller doesn't always reach the end of the s ...

When hovering over different <a> tabs, showcase various images in individual <div> sections

Here are the buttons I am working with - <div class="nav nav-tabs " id="nav-tab" role="tablist"> <a style="text-decoration:none" class="nav-item nav-link" data-toggle="tab& ...

The Material UI button feature neglects to account for custom CSS styles when attempting to override the default settings

Utilizing a custom bootstrap css styles in my react app, I am seeking to enhance the default material ui components with the bootstrap styles. import React, {useState} from 'react'; import 'cg-bootstrap/core/build/cg-bootstrap-standard.css&a ...

How come I am unable to scroll beyond my parallax section unless I move the mouse first?

Currently, I am working on a webpage that includes a Parallax landing image. In order for the Parallax effect to function properly, the image has a greater height, requiring users to scroll down. This leads to the appearance of a second scrollbar specifica ...

Troubleshooting Angular JS loading problems

I'm attempting to implement the Angular-Spinner in my project: Specifically, I want to use it with http.get calls. This is what I have so far: Within controllers: $scope.loading = true; $http.get('js/data/test.json').success(function(resu ...

Using a simulation to deactivate webpage elements and showcase the UpdateProgress control

I am currently attempting to disable certain page elements and display an update progress control in my application. In order to achieve this, I have applied a style sheet with the property filter: alpha(opacity=85); However, I encountered an error stati ...

Tips for locating and substituting a string in Javascript

Is there a way to locate a particular word within a string and substitute it using JavaScript? For instance Here is a lengthy sentence I want to locate the word "sentence" and modify it to "phrase", resulting in: Here is a lengthy phrase ...

jQuery's :last selector allows you to target the last

I need assistance with my jQuery code $('#share_module:last').css("background-color","red"); Unfortunately, it is only affecting the first #share_module Here is an example of the HTML structure: <div id = "share_module" class = "id of the ...

Display website when clicked

When creating a website similar to , one issue that I am facing is the ability to scroll down before clicking the "proceed as anticipated" button. This feature seems to defeat the purpose of having the button trigger an automated scrolling effect if users ...

Remove the <select> highlight specifically for Internet Explorer

Looking for a way to remove the blue highlight in Internet Explorer. I am working with a select tag and whenever an option is chosen from the dropbox, the blue highlight shows up. Unfortunately, I don't have access to IE on my Mac so I can't test ...