Having trouble interacting with buttons while an overlay is open

When I try to use the overlay to move the text upwards and reveal buttons, I encounter an issue where I am unable to hover or click on those buttons. As soon as I try to interact with the buttons, the overlay and text come down, blocking my access.

I have attempted to attach event listeners for mouse enter and leave, maintain a state for it, apply CSS, and use pointer-events. My expectation is that the top element should move above when I hover over the overlay, revealing the buttons. I should be able to hover or click on the buttons to trigger an action. The challenge is to ensure that the top element remains in the hovered state even when I am hovering over the buttons. The overlay should only disable the hover effect when I am outside the entire overlay.

body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  width: 100vw;
}

.container {
  height: 50%;
  width: 50%;
  background: black;
  display: flex;
  justify-content: center;
  align-items: center;
}

.overlay {
  position: absolute;
  top: 35%;
  left: 35%;
  background: blue;
  opacity: 0.3;
  height: 40%;
  width: 30%;
  z-index: 1;
}

.element1 {
  color: white;
  font-size: 3rem;
  font-weight: bold;
  transition: transform 1s;
}

buttonsContainer {
  position: absolute;
  top: 53%;
  left: 45%;
  width: 200px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  opacity: 0;
  transition: opacity 1s;
}

.overlay:hover~.element1 {
  transform: translateY(-100px);
}

.overlay:hover~.buttonsContainer {
  opacity: 1;
  z-index: 3;
}

.btn:hover {
  color: red;
  cursor: pointer;
}
<div class="container">
  <div class="overlay"></div>
  
  <div class="element1">Some texts</div>
  
  <div class="buttonsContainer">
    <button class="btn">b</button>
    <button class="btn">b</button>
    <button class="btn">b</button>
  </div>
</div>

Answer №1

I have discovered an alternative method to achieve this by making some adjustments to the HTML and CSS code. While the CSS code may be slightly incomplete, it successfully accomplishes the goal.

body{
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  width: 100vw;
}

.container{
  height: 50%;
  width: 50%;
  background: black;
  display: flex;
  justify-content: center;
  align-items: center;
}
.overlay{
  position: absolute;
  top: 35%;
  left: 35%;
  background: blue;
  opacity: 0.3;
  height: 40%;
  width: 30%;
  z-index: 1;
  text-align: center;
}

.element1{
  color: white;
  font-size: 3rem;
  font-weight: bold;
  transition: transform 1s;
}

.buttonsContainer{
  margin: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  opacity: 0;
  transition: opacity 1s;
}

.overlay:hover ~ .element1{
  transform: translateY(-100px);
}
.overlay:hover > .buttonsContainer{
  opacity: 1;
  z-index: 3;
}
.btn:hover{
  color: red;
  cursor: pointer;
}
<div class="container">
  <div class="overlay">
    <div class="buttonsContainer">
      <button class="btn">b</button>
      <button class="btn">b</button>
      <button class="btn">b</button>
    </div>
  </div>
  <div class="element1">
    Some texts
  </div>
</div>

You have the flexibility to customize the .buttonsContainer CSS to suit your specific needs. The idea is to nest the .buttonsContainer within the overlay div to maintain the click functionality while preserving the overlay effect.

Answer №2

It's essential to ensure that your hover effect is applied to a stable element, such as the container in this scenario. Utilizing pseudo-elements can help achieve the desired outcome without the need for additional markup.

If your objective is unclear, the provided code snippet can serve as a starting point towards clarification.

body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  width: 100vw;
}

.container {
  height: 50%;
  width: 50%;
  background: black;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  background: blue;
  opacity: 0.3;
  height: 100%;
  width: 100%;
  z-index: 1;
  transition: transform 1s;
}

.container::after {
  content: 'Some Text';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 3rem;
  font-weight: bold;
  z-index: 2;
  transition: transform 1s;
}

.container:hover::before {
  transform: translateY(-100%);
}

.container:hover::after {
  transform: translate(-50%, -200%);
}

.btn:hover {
  color: red;
  cursor: pointer;
}
<div class="container">
  <button class="btn">b</button>
  <button class="btn">b</button>
  <button class="btn">b</button>
</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

Ways to avoid the browser from storing a JSON file in its cache

Hey there, I'm working on a project and running into some issues with caching. The problem I'm facing is that the browser keeps holding onto the json file containing save data even after I update it elsewhere. This means that the browser is readi ...

PHP column number not found

Seeking assistance with a puzzling situation I encountered. My website features a form for administrators to submit user information, including links. The challenge lies in the uncertainty of how many links will be submitted - it could range from 5 to 35. ...

Arranging unrelated divs in alignment

http://codepen.io/anon/pen/Gxbfu <-- Here is the specific portion of the website that needs alignment. My goal is to have Onyx Design perfectly aligned with the right side of the navbar, or to have the navbar extend up to the end of "Onyx Design". The ...

Is it possible to nest a column into another column without a row in React-Bootstrap or Bootstrap?

Is it permitted in React-Bootstrap or React? <row> <col> <col> Is it considered good or bad, or is it allowed? ...

How can I utilize CSS shapes to create clickable images?

I'm facing a challenge in making an input field and button functional even when they are positioned behind a uniquely shaped PNG image. https://i.stack.imgur.com/eOg0N.jpg Initially, I believed that by applying a shape to the image, it would automat ...

What steps can I take to ensure that the full tingle modal, which includes an image, is visible when the

Upon loading the page, I noticed that if the browser width is greater than 540px, the modal displaying an image gets cut off (see figure below). What steps should I take to ensure that the vertical scroll bar appears immediately? https://i.sstatic.net/cJv ...

Are you searching for the origin of a dynamic dropdown widget or database?

Currently, I am browsing through and I have a query regarding accessing all available classes/options for the courses in a semester. There is a class locator on the top left of the page with a dynamic drop-down menu. Can anyone suggest how I can access ...

Expansive full screen image proportions

Is there a way to showcase an image on the entire screen without distorting it, while maintaining its aspect ratio in either HTML or Javascript? The desired outcome is for the image to be centered and: - Have a height of 100% and a width of x% (where "x" ...

Retrieving the background image URL from inline CSS using jQuery

I'm looking for a link similar to url(img/bg/06.jpg), but when using jQuery, I get a longer link like url("file:///D:/WORKING%20FILE/One%20Landing%20Page/version/img/bg/06.jpg") https://i.stack.imgur.com/8WKgv.png Below is the code snippet in questi ...

Configuring Webpack 4 with React framework

Is there a way to automatically reload the application during development mode using Webpack 4? I attempted the following script, but unfortunately it did not work: "scripts": { "dev": "webpack-dev-server --mode development", "build": "webpack --mode ...

"Discover how to set reactstrap collapse to display the first dropdown as active when the page loads for the first time

I'm currently facing an issue with the dropdown functionality in my code. I need the first dropdown to be active on initial load, and then collapse when the user selects a different dropdown option. Can someone assist me with this? Here is a sandbox r ...

Different ways to rearrange the placement of Export buttons in a personalized div or outside the table using Datatable

I would like to display the export buttons outside of the table. While searching on stackoverflow, I came across an example that uses the Select options method. You can find the example here. If anyone knows how to achieve this, please modify it and shar ...

Switching between height: 0 and height:auto dynamically with the power of JavaScript and VueJS

Currently, I am changing the height of a container from 0px to auto. Since I do not know the exact final height needed for the container, using max-height could be an option but I prefer this method. The transition from 0 to auto works smoothly, however, ...

The module was not found due to an error stating: "Unable to locate 'DavidDaDon.png'"

Feeling a bit lost with my code here. I have the PNG files in my src folder, used require and relative paths to access them, but something seems off. What's causing the issue? I'm working on a birthday reminder countdown featuring my closest frie ...

Text-color in the v-tooltip

Is there a way to change the text color of v-tooltips components without affecting the tooltip background color? I attempted to inspect the element, but the tooltip only appears on hover, making it impossible to inspect. Below is the code snippet: < ...

Detecting browser reload in React/Typescript: A guide

Is there a way to determine if the browser has been reloaded? I've explored various solutions, but most suggest using code like this: const typeOfNavigation = (performance.getEntriesByType("navigation")[0] as PerformanceNavigationTiming).type ...

The overflow hidden property does not seem to be effective when used in conjunction with parallax

The issue arises when I attempt to use the overflow hidden property in combination with parallax scrolling. Although everything seems to be working correctly with JavaScript for parallax scrolling, setting the overflow to hidden does not contain the image ...

The modal div remains hidden when embedded inside a PHP file

When I include an agenda.php file that contains a div with the Bootstrap modal class inside another div in a PHP file, it does not display properly. agenda.php <style type="text/css"> .block a:hover{ color: silver; } ...

Tips for updating state in React TypeScript 2.0?

Working with a small component built using React and TypeScript has presented a unique challenge. interface Props { } interface State { isOpen: boolean; } class App extends React.Component<Props, State> { constructor(props: Props) { super ...

Tips for creating a responsive <hr> tag

Help needed with adjusting the horizontal line tag on a webpage created using HTML, CSS, and Bootstrap. The issue arises when the window size changes to extra small. Initially, the hr tag was set to 400px, which looked great on full-screen view. However, ...