The two divs are positioned on top of one another, with the link in the bottom div being unclickable

I am trying to create a unique effect where a tile divides into two on hover, with each tile acting as an individual link. Additionally, I want the background color of the tiles to change on hover.

To achieve this, I have stacked two divs (toptile and bottomtile) on top of each other. On hover, toptile becomes invisible revealing bottomtile, which contains two divs with hyperlinks.

<div class="tile">
    <div class="bottomtile">
        <div class="linktile"><a href="page1.php">ONE</a></div>
        <div class="linktile"><a href="page2.php">TWO</a></div>
    </div>
    <div class="toptile">HELLO</div>
</div>

The CSS:

.tile{
    width: 200px;
    height: 200px;
    position: relative;
}

.bottomtile {
    position: absolute;
    width: 200px;
    height: 200px;
}

.toptile {
    width: 200px;
    height: 200px;
    background-color: red;
    position: absolute;
    top: 0;
    left: 0;
}

.toptile:hover {
    zoom: 1;
    filter: alpha(opacity=0);
    opacity: 0;
}

.linktile{
    height: 95px;
    width: 200px;
    background-color: blue;
    top: 0;
    left: 0;
}

.linktile:hover{
    background-color: yellow;
}

However, I am facing issues with the background change in `.linktile:hover` and the hyperlinks not working as intended. The links seem empty despite displaying the words ONE and TWO. It seems like `toptile` is creating a transparent barrier preventing me from reaching `bottomtile` with my mouse.

I have tried using `visibility: hidden` and `display: none` within the `.toptile:hover` but the problem persists. Is there a way to completely hide `toptile` on hover or any other workaround for this issue?

Answer №1

the reason for this behavior is due to the way you have defined the styling

.toptile:hover {
    zoom: 1;
    filter: alpha(opacity=0);
    opacity: 0;
}

when you use opacity: 0, the element remains present but invisible, making it seem like it has disappeared. This causes the hover effect to still target the .toptile element instead of the intended .linktile, resulting in no change to the background. To fix this, you should utilize display: none and adjust the selector to .tile:hover .toptile since they are not direct parent-child elements. The corrected css should be as follows:

.tile:hover .toptile {
    display: none;
}

you can see the updated code in action on this Fiddle

Answer №2

Change the CSS hover effect from .toptile to .tile

.tile:hover .toptile{
  /* add your code here to hide .toptile */
}

It is true that .toptile covers .bottomtile, making it impossible to interact with. Disappearing .toptile completely would also cause your mouse not to hover over it anymore.

Answer №3

Ride with Luud to your destination. Here is a sleek design concept, complete with cleaner markup.

http://codepen.io/justindunham/pen/sCzcH

.bottomtile .linktile {
  opacity: 0;
}

.bottomtile:hover .linktile {
  opacity: 1;
}

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 store an ES6 Map in local storage or another location for later use?

let map = new Map([[ 'a', 1 ]]); map.get('a') // 1 let storageData = JSON.stringify(map); // Saving in localStorage. // Later: let restoredMap = JSON.parse(storageData); restoredMap.get('a') // TypeError: undefined is not a ...

Using "-webkit-overflow-scrolling: touch" can cause issues with the CSS 3D perspective rendering

Looking for a solution specifically for iOS Safari Using -webkit-overflow-scrolling: touch seems to disrupt the 3d perspective on iOS devices. Check out the demonstration on CodePen. HTML <div class="pers"> <div class="scroll"> <di ...

Having trouble configuring individual route files in Express JS

I'm having trouble separating my login route from the default app.js and route/index.js files. When I try to access localhost:3000/login, I keep getting a 404 Not Found error. I've searched on StackOverflow for similar questions and tried follow ...

Error: TypeScript Knockout table failing to display data

I have a table that displays invoices, along with a nested table showing the individual checks associated with each invoice. I am using knockout and typescript to render these tables. Currently, I can successfully display the invoices but am facing difficu ...

Utilizing adapter headers in contexts other than ActiveModelAdapter

I have successfully implemented my authorization system with Ember Data. All my ember-data calls are secure and signed correctly using adapter.ajax() instead of $.ajax. However, I am facing a situation where I need to utilize a third-party upload library t ...

Multer is successfully retrieving images, but unfortunately, it is failing to save the files in the intended directory

I am currently facing an issue with my Express server. The problem arises when a user attempts to make a post request for their profile, including a profile picture submission. I have set up Multer to handle the image upload process and store the photo in ...

Display hyperlinks upon hovering over text

In the sign-up form, there are options for two different types of users: teachers and students. When the sign-up option is selected, a drop-down menu with choices for teacher and student will appear. However, I would like it to function more like other w ...

Once appearing, the element quickly vanishes after the fadeIn() function is

In the source code, there is a section that looks like this: <div class="dash page" id="home"> <?php include ('pages/home.php'); ?> </div> <div class="dash page" id="screenshots"> <?php include ('pages/scr ...

Trouble getting CSS to load in Webpack

I'm having some trouble setting up Webpack for the first time and I think I might be overlooking something. My goal is to use Webpack's ExtractTextPlugin to generate a CSS file in the "dist" folder, but it seems that Webpack isn't recognizi ...

Setting up proxy middleware in an express application

My application is structured with a frontend server (React) serving static files and a backend server (Express). I have noticed that custom header requests trigger preflight requests, causing latency in my application. My goal is to eliminate these preflig ...

Utilizing form data to upload images and send them back to the front end within a React js application

I am working on a project using NestJS and React JS to create an image uploader. In React, I have the following setup: const props = { onChange({ file, fileList }: any) { const fd = new FormData(); fd.append('img& ...

Transfer a script from a view to application.js in Rails: Guide and Instructions

After conducting some research, I found a code that worked well for me in the view. However, I am looking to transfer it to application.js so that I can utilize it in various forms. Another issue I encountered is having two scripts performing the same fun ...

Transmitting occasional feedback from ASP.NET Web API function to jQuery AJAX

I am currently working on a project that requires sending intermittent status responses from a Web API method back to a jQuery AJAX call in order to display progress in the UI. The process involves the jQuery AJAX calling the Web API method with specific ...

The JSON response may be null, yet the data flows seamlessly to the success function in

Currently, I am facing an issue with Ajax. The situation is as follows: I want to check if a user is available by typing their email address. Therefore, I have created a JavaScript function that includes an Ajax script for this purpose. Here is my code: $ ...

What steps should I take to resolve a plugin error specifically related to index.js while using Cypress?

I am encountering an error in Cypress A plugin has thrown the following error, causing our tests to stop running due to a plugin crash. Please verify your plugins file (/home/dev2/Desktop/kavitaSeffcon/CypressProject/cypress/plugins/index.js) Error: ENOE ...

Creating personalized headers for WebSocket in JavaScript

I am currently in search of a straightforward method to utilize WebSocket with custom headers for a web application, utilizing PHP as the backend and js+vuejs for the frontend. My application needs to establish a connection with a WebSocket server based o ...

Sending form data using javascript without refreshing the page

I have a wall/social system similar to Facebook where users can post statuses. I want to add the functionality for users to like, dislike, and comment on a status without the page reloading. How can I achieve this with the form below? if(empty($_GET[&apos ...

Enhance the brightness and add a subtle glow to an image inside a div element when hovering over the div

Is there a way to create an effect where the image within a div brightens when hovering over the entire div without affecting any other elements? Here is my code, any suggestions or improvements are appreciated. #textimg{ background-image: url( ...

What is the proper way to invoke a function in the code-behind using JavaScript?

I need to invoke a function in the code behind from JavaScript Button : <button class = "btn btn-outline btn-danger dim" type = "button" onclick = "confirmDelete ()"> <i class = "fa fa-trash"> </i> ...

Position divs to be perfectly aligned and centered

I'm in the process of creating a webpage and facing challenges with aligning my divs properly, specifically the animated company logos. I want them to be positioned side by side rather than on top of each other, with space in between to fit the layou ...