Avoid making elements in an overflowing hidden region clickable

Recently, I encountered a situation where the hidden area of an overflowing element still responded to mouse clicks and hovers.

I was under the impression that an invisible element or region would not be affected by mouse events. So, what am I overlooking here?

Here is an example demonstrating this unexpected behavior: hover your mouse outside of the circle but near the green square, and you will see the :hover selector in action.

#circle {
  position:absolute;
  height: 50%;
  width: 28%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: black;
  color: white;
  border-radius: 200px;
  overflow: hidden;
  
}

#square {
  height: 50%;
  width: 50%;
  transform: translate(-50%, -50%);
  background: green;
  cursor: pointer;

}

#square:hover {
  background: yellow;
}
<body>
  <div id="circle">
    <div id="square"></div>
    </div>
    
  </div>

Added on 2016-12-05: Interestingly, this peculiar behavior does not occur in Firefox as some comments have pointed out, unlike in Chrome.

Cheers, utxeee.

Answer №1

As per the W3 specification, the use of overflow: hidden and border-radius should work:

Section 5.3. Corner Clipping

The backgrounds of a box, excluding its border-image, are clipped to fit the specified curve (as defined by ‘background-clip’). Any effects that clip to the border or padding edge (such as ‘overflow’ other than ‘visible’) must also adhere to the curve. The content of replaced elements is always trimmed to the content edge curve. Additionally, the area outside the curve of the border edge does not register mouse events for the element.

However, in practice, it doesn't seem to work correctly (possibly due to a WebKit bug). One workaround is to use the clip-path property (currently supported by all major browsers except IE) like so:

clip-path: inset(0 0 0 0 round 200px);
-webkit-clip-path: inset(0 0 0 0 round 200px);

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

Eliminate the loading spinner from the tab on Google Chrome

Recently, I've been working on a project to create a website and have been searching for some innovative ideas. One interesting discovery I made was . What caught my eye was the unique feature where clicking on any tab did not result in the typical sp ...

Fluid pictures in Mozilla Firefox not fluid

My images are shrinking in Chrome, as expected, but they don't adjust their size in Firefox and IE9. I'm using the CSS below: .pics img { max-width: 100%; height: auto; width: auto\9; /* ie8 */ border: 1px solid #CCC; }​ ...

What is the best way to append a single class while also ensuring any previously added classes are removed?

How can I apply the selected class and remove any previously selected classes? <html> <select name="Button-Style" id="Button-Style" style="width:100%;"> <option value="Sun-Flower">Sun Flower</option> <option value ...

What is the method for specifying the HTML file extension within Visual Studio?

I am having issues with my project recognizing the CSS and other files in the HTML files I have created, even though I have double-checked the extension paths. How can I resolve this problem? https://i.stack.imgur.com/85ooE.png https://i.stack.imgur.com/F ...

Setting Image Height with CSS

I have a div with a height of 105px. The image inside the div is 359px tall. How can I adjust the div's size to prevent cutting off the image and ensure it displays in full height? Thank you for your help! ...

Is there a substitute for image cropping aside from the CSS clip property?

Looking to create an image gallery where thumbnails are cropped to 150px x 150px, but struggling with non-square rectangular images of various sizes. Adjusting width and height distorts the images. Are there alternative CSS or jQuery options for cropping ...

Element positioning in Material UI is fluid and responsive across all devices, with the ability to place elements at

As a novice in layout design, I am currently developing a web application for both mobile and desktop using React and Material UI. My challenge lies in placing the app navigation at the bottom of the screen. The issue arises because the location of the app ...

Attempting to retrieve the list of 'Style' for a GtkWidget

Seeking assistance in obtaining a list of style properties for a GtkWidget (GtkButton). Here is the current code I have: #include <gtk/gtk.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main (int argc, char *argv ...

Using jQuery to modify a CSS property when a specific option is chosen

I'm currently working on creating an option dropdown menu and I've hit a roadblock trying to display a textbox only when the 'other' option is selected. Here's what I have so far: <span id="con-country"><label for="count ...

Why isn't my margin: auto code centering correctly?

My current struggle involves centering a div within the document. While I have successfully achieved horizontal centering, vertical centering remains elusive: width: 950px; height: 630px; background: #FFFFFF; margin: auto; Is it not expected that margin: ...

Guide to transforming Tailwind CSS into a class and saving it in a CSS document

Recently, I implemented Tailwind CSS to style my application. It has been a helpful tool, but I am looking to consolidate all the CSS into one file for better organization. I want to keep it separate from the HTML code. My attempt to convert the following ...

What is the method for rearranging the order of Bootstrap 5 columns within nested elements without using hidden duplicates?

This snippet of code is designed to show blocks in different ways on mobile and desktop devices. <div class="col-12 col-sm-6 order-sm-1">TITLE</div> <div class="col-12 col-sm-6 order-sm-0">IMAGE</div> <div cla ...

Styling applied exclusively to the field for mobile devices

As I work on creating a navigation bar using Bulma and Vue.js, I encounter an issue with the dropdown menu behavior. When the navbar collapses into the hamburger menu, the dropdown list remains in display: block; mode. To address this, I attempted a workar ...

Vuetify vueJS dialog with elevated design

Is there a way to completely remove the elevation of a v-dialog so that it has no shadow at all? The elevation property in the v-dialog itself and using the class as Class = "elevation-0" have not worked for me. Here is the link to the component ...

React eliminates all white spaces

Presented here is a compilation of various span elements: <span>1</span> <span>2</span> <span>3</span> <span>4</span> <span>5</span> Accompanied by the CSS style for these elements: span{ bac ...

The correct rendering of React css only occurs after refreshing the IDE

Can anyone assist me with understanding this unexpected behavior in my CSS? I'm struggling to figure out why it's happening and how to correct the CSS imports. In my react app, there is a single component that imports a stylesheet from a separat ...

What could be the reason for bootstrap failing to recognize and apply my variables?

Whenever I set the text color to green using this code: @textColor: green; It works perfectly and changes the text color, but when I try to modify grid column width and gutter width with this code: @gridColumnWidth: 10px; @gridGutterWidth: 0px; @flu ...

Crafting a sleek arrow-style stepper with Bootstrap 5 breadcrumbs

I am attempting to create a stepper similar to the one showcased in this instance. To add color to the stepper, I utilized the text-bg-success or text-bg-primary classes on the breadcrumb-item as shown below. However, the spacing between the steps appear ...

I am attempting to customize the appearance of a customer Listbox on an HTML page to have a unique pointed head, giving it a distinctive

In my attempt to achieve this design, I have experimented with manipulating the div using a series of nested divs. However, I am struggling to figure out how to position the pointed arrow below the + button. Is it possible to accomplish this effect using C ...

Creating a layout with three rectangular shapes using HTML and CSS

What is the most effective method to achieve the following layout using HTML/CSS: +---------+---------------------------------------------------+ | my | Home About Categories Donate | | best +---------------------------------- ...