Maintain dropdown hover functionality even when circular button and dropdown menu are spaced apart

The main issue I'm facing is due to my insistence on having a circular button. Despite wanting this design choice, the circular shape is causing problems when it comes to hovering over the button. I simply desire a circular <a> button that, when hovered over, will reveal another element below it, whether it be a div or another a tag. These two elements need to be separated by a gap.

I should be able to smoothly move my cursor downwards from the original button to the revealed element without the latter disappearing in between due to the gap separating them. Is there an effective way to achieve this transition without relying on JavaScript?

To kick things off, I've set up a basic structure:

body {
  padding: 30px;
  height: 100vh;
}

#myBtn {
  background-color: grey;
  padding: 20px;
  border-radius: 50%;
}

#hoverInfo {
  display: none;
  margin-top: 40px;
  background-color: green;
  width: 100px;
  height: 50px;
}

#myBtn:hover + #hoverInfo, #hoverInfo:hover {
  display: block;
}
<a id="myBtn" href="/">
  button
</a>

<a id="hoverInfo" href="/">hover info</a>

Let me elaborate on a previous attempt at solving this dilemma:

My initial approach to prevent the vanishing of the second element upon downward cursor movement was to place an invisible hoverable element between elements 1 and 2. This intervening element would ensure that element 2 remains active as the mouse descends towards it. While this tactic would have been effective with all rectangular elements, element 1's circular shape threw a wrench in the plan!

The circular nature of element 1 meant there was only a tiny pixel-wide contact point between the middle hover buffer element and element 1. The circular "corner" gaps prevented proper interaction, making the solution ineffective most of the time.

Even placing the buffer element behind element 1 to fill the circular "corners" proved futile. The bounding box of the circular element thwarted attempts to create a functional area within those corners for mouse interaction, rendering the solution impractical. It may sound confusing, but give it a shot if you manage to implement this peculiar "solution."

Answer №1

One approach is to enclose the circular button within a parent div, serving as the container that triggers the hover effect. By adding padding-bottom, you can simulate the appearance of a gap while ensuring the entire "gap area" activates the hover effect. See the example below, where the wrapper div is given a red background for visualization purposes. Removing the background will restore the intended functionality.

https://codepen.io/xenvi/pen/yLONOEa

body {
  padding: 30px;
  height: 100vh;
}

.buttonWrapper {
  display: inline-block;
  margin-bottom: 40px;
  background: red;
}

#myBtn {
  background-color: grey;
  padding: 20px;
  border-radius: 50%;
}

#hoverInfo {
  display: none;
  background-color: green;
  width: 100px;
  height: 50px;
}

.buttonWrapper:hover+#hoverInfo,
#hoverInfo:hover {
  display: block;
}

.buttonWrapper:hover {
  margin: 0;
  padding-bottom: 40px;
}
<div class="buttonWrapper">
  <a id="myBtn" href="/">
  button
  </a>
</div>

<a id="hoverInfo" href="/">hover info</a>

Answer №2

If you want to enhance the hoverable area for an element, you can easily achieve this by utilizing a pseudo-element that becomes active only on hover:

body {
  padding: 30px;
  height: 100vh;
}

#myBtn {
  background-color: grey;
  padding: 20px;
  border-radius: 50%;
  position:relative;
}
#myBtn:before {
   content:"";
   display:none;
   position:absolute;
   top:90%;
   left:0;
   right:0;
   height:28px;
}

#hoverInfo {
  display: none;
  margin-top: 40px;
  background-color: green;
  width: 100px;
  height: 50px;
}

#myBtn:hover::before {
  display:block;
  background:rgba(0,0,255,0.2); /* to illustrate */
}
#myBtn:hover + #hoverInfo, #hoverInfo:hover {
  display: block;
}
<a id="myBtn" href="/">
  button
</a>

<a id="hoverInfo" href="/">hover info</a>

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

Displaying an element to appear over all client applications when hovering

Currently, I have an application that highlights specific areas when hovered over or clicked. While it functions properly, I would like the hover and click effects to be visible on every client, each with an identical overlay setup. I realize my method may ...

Load Angular template dynamically within the Component decorator

I am interested in dynamically loading an angular template, and this is what I have so far: import { getHTMLTemplate } from './util'; const dynamicTemplate = getHTMLTemplate(); @Component({ selector: 'app-button', // templat ...

Displaying an array value instead of a new value list in a React component

Situation - Initial number input in text field - 1 List of Items - 1 6 11 Upon removing 1 from the text field, the list becomes - New List Items - NaN NaN NaN Now, if you input 4 in the field. The updated List Items are - NaN NaN 4 9 14 Expected ...

The concept of CSS sprites and managing background positions

I have been working on integrating a star-rating widget that requires the use of a sprite file. The sprite file I am using looks like this: https://i.stack.imgur.com/ZSMMj.png This is how my HTML is structured: HTML <span id="star-ratings" class="c ...

How come the nth-child selector remains unaffected by other selectors?

Here is an example that I have created for this issue: http://jsfiddle.net/SXEty/ <style> table td, th { padding: 8px; text-align: left; } table td:nth-child(1) { color: red; } table td { color: blue } </style> ... <table> <tr> ...

How can we use a :before tag element to create a hovering effect on an image that remains clickable?

My objective is to create an image that is wrapped in a link. The link will have a pseudo element :before that adds a black overlay on hover. I want the image to remain clickable, but no matter what I try, the pseudo element won't position correctly o ...

Tips for ensuring the list stays perfectly centered within the navigation bar when placed among three images

I have my navigation bar set up with the logo on the far left and two flags for English and Italian on the far right. The issue I'm facing is that the UL element, being a block element, pushes the flags onto the next line. However, I want the UL to be ...

What's causing the HTML body to be fixed at the top of the viewport?

Currently, I am in the process of developing a commandline tool to quickly generate an HTML Bootstrap starter template for my personal use. The main issue I am facing is with the index page, where a basic navigation bar should be displayed at the top, and ...

What is the best way to add a sub menu to a "ul" element without modifying the original parent "ul" or impacting its siblings?

I am trying to add a nested <ul> element inside a specific <li> element in my menu structure without affecting any other elements. I want to increase the depth of the parent menu item while keeping the siblings unchanged. This is the current H ...

The directory structure does not align with the 301 redirect

I recently transitioned my website from HTML to a CMS platform. The new CMS does not include any file extensions in the URLs, so I have maintained the same URL structure from my old HTML site. Here is an example of the difference: HTML site URL: www.sit ...

What's the ideal file structure for Codeigniter paired with Angularjs?

Recently, I embarked on a project using Codeigniter and AngularJS for an app. However, I encountered some issues when attempting to use font-awesome offline. After investigating the problem, I concluded that it may be related to the file folder structure ...

Troubleshooting spacing problems in Angular Material tables

I'm attempting to utilize an Angular Material table in the following way: <div class="flex flex-col pb-4 bg-card rounded-2xl shadow overflow-hidden"> <table mat-table class="" [dataSource]="$candidates ...

Using a snippet of HTML code from one Angular component in another component

Is it possible to use a specific div element from one Angular component in another component? main component.html <html> <div1> some elements </div1> <div2> some elements </div2> In the child ...

The document type is not compatible with the "div" element in this section. You must include one of the following start-tags: "object", "ins", "del", "map", or "button"

When I run W3C validation, it indicates an error on the line below: <div id='main' style='border:1px solid #999;'> This error appears in the following code snippet: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "h ...

Choosing one element from various options in multiple forms

I'm encountering an issue with selecting a specific element from multiple forms in my JavaScript code: The current JavaScript function I am working with is as follows: function makeActive(target) { $("div.interactive").removeClass("interactive") ...

Show all span elements in a map except for the last one

Within my ReactJS application, I have implemented a mapping function to iterate through an Object. In between each element generated from the mapping process, I am including a span containing a simple care symbol. The following code snippet demonstrates t ...

Validation of HTML5 forms using jQuery

I am in need of a jQuery-based validation library that will kick in when the browser does not support HTML5 for specific attributes like 'required' or 'placeholder'. After looking around, I have come across several libraries but they ar ...

Navigating between divs with a 100% height using up and down movements

I am working on a website that is structured into different sections using divs with shared classes but unique IDs. Each div is set to take up 100% of the viewport height. To navigate between these sections, I want to provide Up/Down arrow buttons for user ...

Increase the border thickness around my title and add a border after an image

I'm encountering difficulties when trying to replicate the style showcased in this image using CSS. My specific challenge lies in creating a yellow horizontal line above the title "nossos numeros" and blue vertical lines between "Cursos", "Alunos", an ...

Enhance <th> elements using CSS classes

I'm encountering some issues with HTML tables. The layout of my table is as follows: <table class="shop_table cart" cellspacing="0"> <thead> <tr> <th class="product-remove">&nbsp;</th> <th clas ...