Button overlay is unresponsive to clicks

I've been working on creating web-based slides from scratch, but I'm running into an issue with getting a toolbar to display above each slide - the buttons aren't responding when clicked. To demonstrate this problem, I've set up a sample code snippet below. When you click on the button, nothing happens except that it registers a click on the slide itself. Interestingly, the z-index of the button is higher than that of the slide.

Is there a way to keep the elements in their current position within the tree and still make the button clickable?

#fullscreenbutton {
  z-index: 1001;
}
.slides {
  display: block;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 */
  position: relative;
  overflow: hidden;
}
.slide {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 100%;
  font-size: 1.5vw;
  padding: 20px;
  box-sizing: border-box;
  z-index: 1000;
}
<div id="app">
  <div class="slides" id="slides">
    <button id="fullscreenbutton" onclick="this.style.color='red'">Make me red</button>
    <div class="slide" ignore-position="current">
      this slide overrides everything
    </div>
  </div>
</div>

Answer №1

To solve this issue, an effective approach is to eliminate non-css functionalities from the base element:

.slide {
   ...
  pointer-events: none
}

Example on Fiddle

Answer №2

div.slide is positioned in front of the button, allowing it to capture all events.

In my opinion, a practical solution would be to have all controls placed within a distinct, absolute .div that sits in front of the slides.

Answer №3

Ah, finally located the solution – simply had to configure

position:absolute;

for the element #fullscreenbutton.

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

How to use jQuery to toggle a specific div within a PHP loop

In my PHP code, I have a while loop that echos rows inside a div acting like a button. When this button is clicked, I want to hide/show the connected div using jQuery's "toggle" function. Currently, when any button is clicked, all divs open instead of ...

Is it possible to center my tab on the page and add captions as well?

Struggling to align a tab with 3 image buttons in the middle, I resorted to using manual margin adjustments. I also added captions separately from the buttons for aesthetic purposes, but know this is not the correct way. Is there a way to attach the captio ...

Unable to create slides with Fancybox if the content is in HTML format

I'm not sure if this issue is a bug or if it's just a restriction of fancybox. Can anyone confirm if it's possible to create a gallery using HTML elements? I've been attempting to accomplish this for hours without success. Here is the ...

Ways to pinpoint a particular division and switch its class on and off?

Consider this scenario, where a menu is presented: function toggleHiddenContent(tabClass) { let t = document.querySelectorAll(tabClass); for(var i = 0; i<t.length; i++) { t[i].classList.toggle="visible-class"; } } .hidden-conten ...

Utilize the data-toggle attribute to retrieve a unique variable name, which can then be integrated into a function for added

I'm in the process of replacing an iframe with an image, and I want to accomplish this with minimal code. The container div I'm working with has a data-toggle attribute: <div id="my-div" data-toggle="video2"> <div id="videocontaine ...

Check the box if the text can be found in the list

In order to toggle the checkbox marked in blue on the image, I need to verify if the checkbox is associated with a specific label in the list. My script should follow these steps: Proceed to the settings section. (Dune) Retrieve the names of all menus. ( ...

Expand child elements within the parent container to fill the entire width of the browser

Does anyone know how to make a nested child element the full width of the browser? I've tried using position absolute and setting left and right to 0, but it's not working as expected. You can see what I'm trying to do in this fiddle: http: ...

Stop scrolling when hovering over an element

I'm currently working on animating a scrolling div and have managed to get the trigger to fire, scroll, and stop on click and/or mouseenter. However, I am now looking to make it pause when the mouse hovers over the div instead of stopping altogether. ...

The sequence of HTML attributes

Could there be a subjective angle to this question (or maybe not)... I work on crafting web designs and applications using Visual Studio and typically Bootstrap. When I drag and drop a CSS file into an HTML document, the code generated by Visual Studio loo ...

React Native Bug: Border Radius Issue at the Bottom

I'm struggling with adding a border on the bottom and left sides. Even though I've specified the properties, the border is covering the circle instead of surrounding it. <View style={{ borderBottomColor:'red', borderBotto ...

What could be causing Prettier code formatter to suddenly stop formatting in VS Code?

I've been having trouble formatting my code using Prettier in VS Code. Even after reinstalling it, the issue persists and I can't seem to format my HTML/CSS code properly. The screenshot I provided shows that the code remains unformatted even aft ...

Is there a way to update components in Angular without affecting the current URL?

I want to update a component without changing the URL. For example, I have a component called register. When I visit my website at www.myweb.com, I would like to register by clicking on sign up. How can I display the register component without altering the ...

I am facing an issue where Bootstrap button classes are duplicating when I inspect the code. How can I resolve this

Can anyone help me with an issue I am facing with a Bootstrap button? Despite using only the btn btn-default classes, when inspecting it in Chrome, multiple classes are being displayed on the button. I'm unable to figure out why this is happening and ...

Extracting Table(Array) Index into a Component in Angular

For my data on the HTML page, I created a 2-dimensional array. <tbody> <tr *ngFor="let i of myarray2"> <td *ngFor="let j of i"> {{j}} </td> </tr> </tbody> This is how it appears: https://i.sstatic.ne ...

Aligning Header and Search Icon in Perfect Harmony with the Body

I've been struggling with alignment issues on my Tumblr blog. Specifically, I'm trying to align a header and a search icon. You can find my site here. Here is the mockup I am aiming for: However, if you visit my site, you'll notice that ...

The functionality of the Bootstrap dropdown list button is not functioning properly on mobile devices

Currently, I am in the process of developing a website and testing its mobile view on my iPhone. The website is still using bootstrap 3, but I have encountered some issues. When I tap on the navigation button on my iPhone, nothing happens - no dropdown lis ...

The art of positioning Bootstrap popovers

Does anyone know a way to position a bootstrap popover on the "Right Bottom" of a clicked button instead of the "Right Middle"? The positioning should be dynamic. https://i.sstatic.net/OSQln.png To see the standard code, click here: http://jsfiddle.net/V ...

How to Utilize ngIf and ngFor Together in Angular 4 for the Same Element in ngFor

Just starting with Angular 4 and experiencing a roadblock in my code. Here is the snippet of my code: JSON: [{"name": "A", "date": "2017-01-01", "value": "103.57"}, {"name": "A", "date": "2017-01-08", "value": "132.17"}, ...

How can I change a textarea to uppercase?

I'm looking to create a textarea that automatically types in all capital letters, regardless of the user's input or whether they are holding down the shift key. I want it to accept any input and convert it to uppercase on the fly without showing ...

Sending a PHP variable to a JavaScript function when calling it on a different webpage

As I am working on a code that involves three files, let me break it down for you. The files in question are referred to as a, b, and c. We have "File a," which is an HTML file, "File b," an HTM file, and finally, "file c," which is a PHP file. In "File a ...