Misaligned CSS borders with content

Hey there!

I recently updated my dropdown menu by adding borders, but I'm facing an issue where the hover color doesn't align perfectly with the border, leaving a small line visible.

https://i.sstatic.net/dianL.png

Interestingly, hovering over the line selects the parent element, but not the actual object itself, making it unclickable.

I need to adjust the hover style to align with the border and eliminate the dark stripe in front of the cell.

You can view the problem here: https://jsbin.com/cejigelobi/edit?html,css,output Click on the 3 lines -> Click on Products -> Hover over a submenu to see the issue.

HTML:

:root {
  --background-color: #001728;
  --darker-background-color: #000000;
  --accent-color: #20cc5b;
  --text-color: #FFFFFF;
  --navbar-height: 80px;
}

* {
  margin: 0;
  padding: 0;
  font-size: 22px;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text-color);
}

html {
  height: 100%;
}

body {
  height: 100%;
  background-color: var(--background-color);
}

nav {
  height: var(--navbar-height);
  background-color: var(--background-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 4px solid var(--accent-color);
}

nav .logo {
  margin-left: 30px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 35px;
  font-variant: small-caps;
  text-decoration: none;
}

nav ul {
  height: 100%;
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  align-items: center;
  list-style: none;
}

nav li {
  height: 100%;
  width: 150px;
  text-align: center;
  position: relative;
}

nav li:hover {
  background: var(--accent-color);
}

nav ul a {
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.dropdown {
  height: min-content;
  width: 200px;
  background: var(--background-color);
  box-sizing: border-box;
  border-left: 2px solid var(--accent-color);
  border-right: 2px solid var(--accent-color);
  border-bottom: 4px solid var(--accent-color);
  display: none;
  flex-direction: column;
  position: absolute;
  left: 0;
  top: var(--navbar-height);
}

.dropdown li {
  height: 70px;
  width: 100%;
}

.dropdown li a {
  justify-content: flex-start;
  padding-left: 30px;
  width: calc(100% - 30px);
}

nav li:hover .dropdown {
  display: flex;
}

nav input[type="checkbox"] {
  display: none;
}

.expandable_li {
  display: flex;
  justify-content: center;
  align-items: center;
}

.toggle_button {
  width: 30px;
  height: 23px;
  position: absolute;
  top: 25px;
  right: 25px;
  display: none;
  flex-direction: column;
  justify-content: space-between;
}

.bar {
  height: 4px;
  width: 100%;
  background: var(--text-color);
  border-radius: 100px;
}

@media(max-width: 850px) {
  .toggle_button {
    display: flex;
  }
  nav ul {
    height: min-content;
    width: 100%;
    background: var(--background-color);
    display: none;
    position: absolute;
    top: var(--navbar-height);
  }
  nav li {
    height: min-content;
    width: 100%;
  }
  nav ul a {
    padding: 30px 0;
  }
  .expandable_li {
    display: block;
  }
  .expandable_li label {
    padding: 30px 0;
    cursor: pointer;
    display: block;
  }
  .expandable_li:hover .dropdown {
    display: none;
  }
  .expandable_li input[type="checkbox"]:checked~.dropdown {
    display: block;
  }
  .dropdown {
    position: static;
    width: 100%;
  }
  .dropdown li {
    padding: 0;
    display: block;
    position: static;
  }
  .dropdown li a {
    width: 100%;
    padding: 0;
    justify-content: center;
  }
  #toggle_button:checked~ul {
    display: block;
  }
}
<nav>
  <a class="logo" href="#">wesodev</a>
  <input type="checkbox" id="toggle_button">
  <label for="toggle_button" class="toggle_button">
            <span class="bar"></span>
            <span class="bar"></span>
            <span class="bar"></span>
        </label>
  <ul>
    <li><a href="#">Home</a></li>
    <li class="expandable_li">
      <input type="checkbox" id="products_checkbox">
      <label for="products_checkbox">Products</label>
      <ul class="dropdown">
        <li><a href="#">Financist</a></li>
        <li><a href="#">Coming Soon</a></li>
        <li><a href="#">Coming Soon</a></li>
      </ul>
    </li>
    <li><a href="#">About</a></li>
    <li><a href="#">Contact</a></li>
  </ul>
</nav>

Answer №1

Appreciate your help, Pete! To fix this issue, the border should be placed on the .dropdown li element rather than the .dropdown.

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

What is the best way to create a mobile menu transition that moves in a "reverse" direction?

I have been working on animating a mobile menu where the three stripes transform into an 'X' when clicked and revert back to three stripes when closed. The transition to an 'X' is working perfectly, but when closing the menu, it jumps b ...

Having trouble with the float not working for the main content below the sidebar? Stay tuned

Here is the layout I am working with: .page-wrapper { height: 100%; min-height: 970px; position: relative; } .pageheader { min-height: 50px; position: fixed; min-width: 100%; } .navbar-fixed-top { top: 0; } .page-sidebar { float: left ...

Conflicting media queries

Attempting to resolve the issue of site content overlapping with the background slider plugin on a WordPress website, I have encountered conflicting media queries for different devices. While it may work perfectly on mobile devices, it can create problems ...

Issue with content not wrapping inside the body tag (apart from using float or setting body and html to 100

Why on earth is the body/html or .main div not wrapping my .container div's when the browser width is between 767-960 px?! This is causing horizontal scrolling and I am completely baffled. This should definitely be working! The only code I have is: ...

Ensure that the child div is anchored to the bottom of the parent div container

I am looking for a way to ensure that the subfooter div stays at the bottom of the childbox div, similar to a footer. You can view the code on this jsfiddle link <div class="parentbox"> <div class="childbox"> <div id="subfooter" ...

What is the best way to design a group of radio buttons with corresponding labels at the top

I'm looking to create a structure like this in HTML: https://i.sstatic.net/wLcZs.png Does anyone know how I can achieve this layout so that the labels are aligned properly with the radio buttons? My main challenge is getting the horizontal labels ab ...

Ways to arrange Bootstrap 4 navigation bar links side by side and align them to the right

I am facing a challenge in designing a navigation bar where the brand logo is on the left, while the navigation links are placed on the right. Currently, the links appear stacked on top of each other instead of side by side: <link href="https://maxcd ...

Adjusting position in relation to the cursor's movements

I have searched extensively for similar questions but have been unable to resolve my issue. Here, I am sharing just a single list item from my code. The task at hand is to create a span element on the mousemove event over the list item, and dynamically set ...

Why can't we use percentages to change the max-height property in JavaScript?

I am currently working on creating a responsive menu featuring a hamburger icon. My goal is to have the menu list slide in and out without using jQuery, but instead relying purely on JavaScript. HTML : <div id="animation"> </div> <button ...

Using Vue to toggle an active HTML class on click: A tutorial

Can someone assist me with this code snippet that is intended to toggle a class using a Vue on-click event? I'm encountering issues as it's not working and I'm seeing several errors in the console. Any help would be appreciated. <div id=& ...

What is the best way to pinpoint a specific Highcharts path element?

I am currently working on drawing paths over a graph, and I am looking to dynamically change their color upon hovering over another element on the page - specifically, a list of data points displayed in a div located on the right side of my webpage. Below ...

"Looking for a quicker way to upload images without the hassle of a long input field? Learn how to use a glyphicon

Is there a way to use a symbol or glyphicon for uploading an image instead of having to use such a long input field? (Specifically for uploading a profile picture) I'd like the ability to click on the glyphicon and choose an image from my computer. T ...

As I scroll, the background color of my body vanishes

Seeking assistance with a CSS issue. I have set the height property of my body to 100%, which works well when all content is visible on screen. However, when I need to scroll due to window size changes, the body color disappears and only the HTML backgro ...

The initial display of jqGrid columnChooser may not show the expected effect on the first attempt

Trying to implement jqGrid in my project has been mostly successful, but I am encountering two specific issues: The first time the columnChooser is clicked, it does not display the effect when clicking the done button. However, it works as intended on th ...

Encountering the error message "Uncaught TypeError: Unable to assign value to property 'color' of an undefined object"

I'm facing an issue where I am trying to change the color of the button text to "white" when the button is clicked. However, upon clicking the button, I encounter an error that says "Uncaught TypeError: Cannot set property 'color' of undefin ...

What is the best way to transfer a row from one table to another using jQuery by selecting the row and then clicking to move it?

As a newcomer to stackoverflow, I am encountering an issue while working on two tables. There is a right button that should move the row into the next table, but unfortunately, my attempts to make it work have been unsuccessful. I would greatly appreciate ...

Looking for assistance in crafting the flag of Iceland using only HTML or CSS coding

Can someone assist me in coding the flag of Iceland using only HTML and CSS, without using any images? Your help is greatly appreciated. https://i.sstatic.net/ND6bq.png ...

The issue of viewport device-height not functioning properly on Mobile Safari

I'm currently working on a web app for an iPad 3, but I'm facing an issue with the vertical scroll functionality. Strangely, this problem hasn't occurred when developing similar apps in the past, so I'm unsure of what's causing it ...

Creating a fixed list with top-sticking elements on a webpage using HTML

Creating a single page webapp using Vue/Vuetify, I am facing an issue with building a list (v-list) of items on the right side that requires scrolling. Even though the list is longer than the page height, I want to prevent the rest of the page from scrolli ...

Explore our interactive map and widget features that will seamlessly fill your browser window for a

Struggling to make a webpage with a Google Map, Chart, and Grid expand to fill the available space on the screen. Tried various CSS tricks but nothing seems to work. Check out this simplified example in JsFiddle that showcases the issue: http://jsfiddle. ...