Showing a DIV container upon hovering over a different element

Having trouble with a hidden div container not displaying properly upon hovering over a visible div container.

When d1 is hovered over, d2 appears but with a blinking effect. Here is my code:

Note: I want d1 to remain visible and use d2 for displaying text over d1.

http://jsfiddle.net/3ey778vc/

CSS:

.website{
    width:400px; height:400px; background: black;
}

.website .d1, .website .d2{
    width:100%; height:100%; float:left; 
}

.d1{
    background:red;
    width:100%; height:100%; float:left
}

.d2{
    background:blue;
    margin-top:-400px; display:none;                z-index:100;
}

.d1:hover + .d2 {
    display: block;
}

HTML:

<div class='website'>
    <div class='d1'></div>
    <div class='d2'></div>
</div>

Answer №1

.page {
    width:400px; height:400px; background: black;position:relative;
}                   
.page .section1, .page .section2 {
    left:0px;top:0px;width:100%; height:100%;
}
.section1 {
    background:red;
    width:100%; height:100%; z-index:0;position:relative;
}
.section2 {
    background:blue;
    display:none;               
    z-index:100;
    opacity:.5;
    position:absolute;
}

.page:hover .section2 {
    display: block;
}

By using this layout, you can stack one section on top of the other. Notice the cool blue hue, created by the opacity setting, to showcase the visual effect.

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

Apply a 2 pixel top border to an HTML table

Is there a way to add a double border at the headcell without using background images? Currently, I have a white color border top and want to add a grey color border on top of the white one. Is it possible to achieve something like #ccc and #fff for borde ...

Using jQuery to combine a variable with the image source in order to replace the image attribute

I am trying to create a script that will display a greeting message to the user based on their local time. I found a script on Stack Overflow, but I am struggling with updating the image source. When I try to replace the image source, I encounter the follo ...

What's the best way to vertically center a div with a 100% width and a set padding-bottom on the screen?

I am struggling with positioning the following div on my webpage. .div { width:100%; padding-bottom:20%; background-color:blue; } <div class="div"></div> I have been searching for a solution to vertically center this responsive div on my web ...

Retrieve and substitute attributes using preg_replace

I'm looking to add tabs to all the properties listed here, but I am having trouble isolating the properties as $1 is not working in this case. A small tweak would solve this issue... Thank you! $css = <<<EOF body { padding: 0px; ...

Adjusting image size to fit divs depending on orientation

I am currently working on a project where I need images to fill a div while still maintaining their aspect ratio. To achieve this, I am utilizing jQuery to determine if the images are portrait or landscape, and adjusting the width or height accordingly. H ...

What is the best way to showcase a JSON object in an attractive format on a webpage?

Similar Question: JavaScript data formatting/pretty printer var theobject_string = '{...}'; // I have a JSON object as a string. Is there a way to present this string in a visually appealing manner on an HTML webpage? I would like the ...

Creating Dynamic Website Titles with PHP and HTML

I am currently teaching myself web development and using the W3 validator to check my code. I have a document that loads like this: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Conten ...

Having trouble resolving a setInterval problem with JavaScript?

Yesterday, I learned about the setInterval function which allows me to execute a task or function after a specific amount of time. While I have successfully implemented the interval in my code, it keeps adding new lines with the date each time. What I re ...

What is the reason for object destructuring not functioning properly in styles?

Why is it that the HTMLelement is considered an object, while the style is also an object, yet this code fails to work as expected? When I remove destructuring, everything functions properly, so I am curious to understand the underlying reason behind thi ...

Using jQuery to select and animate several elements simultaneously without repeating the animation

Issue Summary (Fiddle): I'm trying to make all elements fade out simultaneously when clicked, but the current code causes the target to trigger three times resulting in three alert() calls. I want them to fade together without using a wrapper element ...

Center 3 elements horizontally using Flexbox, ensuring the center element is aligned properly

Is it possible to center 3 elements using flexbox on a page? The middle element should be centered on the page, while the left and right elements can vary in width. Please refer to the image below: https://i.sstatic.net/IVdz8.png I am not certain if this ...

Ways to center text in a div using vertical alignment

/* Styles for alignment */ .floatsidebar { height: 100%; float: left; overflow: hidden; width: 30px; line-height: 1.5; } .vertical-text { height: 100%; display: inline-block; white-space: nowrap; transform: translate(0, 100%) rotate(-90 ...

Timeout for browser response

Currently working on Perl CGI scripting within HTML, my script utilizes send expect and print statements. To prevent the browser from displaying the send expect results, I included $exp->log_user(0). When running the script in the browser, only the prin ...

Enhancing the aesthetic appeal of a form

I have created a form in HTML that utilizes JavaScript to pull data from a database. I am looking to style the form, but I'm unsure of how to proceed. Below is the form along with some CSS code. How can I integrate the two together? <form id=" ...

Can you suggest a method to save cookies or HTML5 localStorage across multiple WebBrowser instances on Windows Phone?

Quick question: How can I save data from Javascript in a WebBrowser control on my Windows Phone 8 app so that it remains even after the user closes and reopens the app? In more detail: I am working on a Windows Phone 8 app with a single WebBrowser contro ...

Applying a distinct CSS style to the final entry of each list item

Is there a way for me to assign a different style for the last entries in my code? <?= $k % 2 == 1 ? 'news-figure' : 'news-figure-b' ?> ...

Extend the width of a div element to fit the size of its absolutely positioned

I am facing an issue with a Div that contains multiple absolutely positioned divs. The clickable area of the main div expands to cover the children, but the drawn area does not. I need the drawn area to encompass all the container divs. You can view a JSF ...

Achieving navigation bar functionality in Bootstrap using jQuery

Is there a way to make the navbar active when it is clicked? Below is the jQuery code I am currently using: $(document).ready(function () { $('.navbar li').click(function(e) { $('.navbar li').removeClass('acti ...

Tips for coloring just the letters and excluding the Bengali Kar symbol

The Bengali language consists of 40 consonants, including ক, খ, গ, ঘ, ঙ, চ, ছ, জ, ঝ, ঞ, and more. Additionally, there are 10 vowels in the form of Kars, such as া, ি, ী, ু, ূ, ৃ, ে, ৈ, ো, and ৌ. My goal is to highli ...

I'm experiencing an issue when trying to align TextPath to the center in an SVG file - a certain character

When using the startOffset or text-anchor attributes, I noticed that some characters are missing. How can I fix this issue? Thank you. It appears that in this scenario, the characters `1234` are missing. <svg xmlns="http://www.w3.org/2000/svg" versi ...