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 prevent input fields from wrapping onto a new line in a Bootstrap 4 inline form layout?

I am facing an issue with my inline form where the input fields are wider than the screen, causing some of them to fall onto a new line. <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="u ...

Is there a way to delete highlighted text without using execCommand and changing the font color

With my current use of JavaScript, I am able to highlight or bold a selected text range successfully. However, I am unsure how to undo the bold and unhighlight the text if the button is clicked again and the selected range is already bolded or highlighted. ...

Is there a way to extract headers from this ajax call?

I keep getting a 302 exception with this script, but I'm unable to retrieve the Headers from the response. Even though I can see the header location in the console returning a new URL, the script doesn't seem to be able to access it. Can anyone ...

angular-chart custom tooltip positioning issue

Hello everyone! I'm having trouble fixing the tooltip position when hovering over a point. I've searched through various posts on StackOverflow and have tried all the examples provided in my implementation: https://github.com/chartjs/Chart.js/tr ...

How to pass arguments to the `find` method in MongoDB collections

I've been attempting to pass arguments from a function to the MongoDB collection find method. Here's what I have so far: async find() { try { return await db.collection('users').find.apply(null, arguments); } catch(err) { c ...

Should you consider using the Singleton pattern in Node.js applications?

After stumbling upon this specific piece discussing the creation of a singleton in Node.js, it got me thinking. The require functionality according to the official documentation states that: Modules are cached after the first time they are loaded. Multi ...

Continue running web AJAX request in Android browser while it is minimized

I need help with my AJAX call var tid = setInterval(mycode, 2000); function mycode() { $.ajax({ url:'/ajx.php', type: "GET", success: function (data) { }, ...

steps to activate button once the form is validated

Can you provide guidance on disabling and enabling a button when the form is valid? I have several conditions in my form: Name on Card: Should only contain English alphabetic letters. Card Number: Must consist of exactly 16 numbers. Expiration Month: A ...

Moving elements using CSS

Hi, I've been facing this issue with my web development since the start. Whenever I zoom in, the container also moves along. Is there any way to fix this problem? .darkslidecont{ width: 200px; height: 50px; position: relative; bac ...

update the componentWillMount() function

I am currently exploring the code found at https://github.com/Spyna/react-store/blob/master/src/createStore.js What adjustments do I need to make in order to align with the deprecated componentWillMount lifecycle method? CreateStore const createStore = ...

When using res.render to pass data to an EJS file and accessing it in plain JavaScript

I'm currently working on an Express GET function where I am sending data to an EJS file using the res.render() function. My question is, how can I access this data in plain JavaScript within the same EJS file? Here is my GET Function: router.get(&a ...

What strategies would you use to put in place conditional imports in a way that is reminiscent of ReactNative

Is there a way to implement conditional imports in other projects similar to how React Native imports Android or iOS specific classes using *.android.js and *.ios.js? If I wanted to have different classes for development and production purposes, could I u ...

bootstrap 4 appears to encounter some responsiveness issues when it comes to rendering on iPhone

https://i.sstatic.net/rdOtX.png While inspecting my website on mobile using developer tools, everything looks perfect. However, when I view it on my actual iPhone 6, the layout seems off. Could this be a bug specific to the iPhone 6? Here are my meta tag ...

Tips for creating an auto-incrementing ID within Firebase's real-time database

How can I create an automatic incrementing ID for entries in a Firebase database? The first item should have an ID of 1, and the second one should be 2. var database = firebase.database(); var userDetails = database.ref("Article"); userDetails. ...

Exploring the Past: How the History API, Ajax Pages, and

I have a layout for my website that looks like this IMAGE I am experimenting with creating page transitions using ajax and the history API. CODE: history.pushState(null, null, "/members/" + dataLink + ".php" ); // update URL console. ...

Can a Textmate snippet be activated using a Regex pattern instead of just a specific character?

Hey there, I've been spending a lot of time working with CSS recently, and I have to admit that constantly typing "px" after every width, height, margin, etc., is starting to get on my nerves. I find myself refining pixel values in Firebug quite ofte ...

Chrome and Firefox: Images cling together

I've encountered an issue with my recently launched website. Some images in a grid appear to be stuck together, but this problem only occurs in Firefox and Chrome browsers. Oddly enough, zooming in to around 110% then back to 100% seems to temporarily ...

Leveraging summernote in meteor with Discover Meteor tutorial

Recently, I've been delving into the world of Discover Meteor and encountering some challenges along the way. My current hurdle involves integrating content entered in summernote into mongo, but it seems to be more complicated than expected. The fil ...

Ways to identify when the socket has been opened by the client?

When utilizing socket.io on the client browser side, is there a way to identify when the socket connection has been successfully opened? I am also interested in monitoring other standard messages such as errors and disconnections. In comparison to the Web ...

Oops, seems like there was a problem with parsing the

I have encountered an issue when trying to decode the value of a PHP array sent as JSON format. Here is how I created the array: $ads = $atts['ads']; if (sizeof($ads) > 0) { foreach($ads as $social_item) { $sdbr = $social_ ...