hi everyone,

im having some trouble with design im working on.

Basically what i want to achieve is when the user hovers on an image, a semi-transparent black box pops up over the image with a description.

I have tried a few ways but am now stuck for ideas.

My first solution was to make it popup with javaScripts onmouseover but this wouldnt work because the popup then goes over the image so the cursor is now not over the image.

Ive tried doing it the way i make some of my navigation bars with a display:none ul and li menu but again no such luck.

In the words of Jar Jar Binx "Any help here would be hot" :)

Thanks

Dani AI

Generated

Nice work — your CSS-only overlay idea is the right direction. Two practical tweaks will make it more robust: trigger the overlay from the container (so showing the overlay does not remove the hover), and animate only opacity/transform (not position/size) for smooth, GPU-accelerated transitions. 's z-index tip is useful when you have multiple stacked elements, but pointer-events and container-based :hover remove the original "cursor leaves the image when overlay appears" problem.

Example (semantic markup + CSS-only hover, different from the code already posted):

<figure class="thumb">
  <img src="images/tut4.jpg" alt="Sketch-material tutorial preview">
  <figcaption class="overlay">
    <p>In this tutorial we look at two ways to create sketch materials...</p>
    <small>Running time: 9:20 • Level: Intermediate</small>
  </figcaption>
</figure>
.thumb { position: relative; display: inline-block; width: 340px; overflow: hidden; }
.thumb img { display: block; width: 100%; height: auto; }

.thumb .overlay {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  background: rgba(0,0,0,0.75);
  color: #fff;
  padding: 12px;
  opacity: 0;
  transition: opacity 300ms ease;
  display: flex;
  align-items: center;
  pointer-events: none;   /* allow hover to reach container while hidden */
  will-change: opacity;
}

.thumb:hover .overlay,
.thumb:focus-within .overlay {
  opacity: 1;
  pointer-events: auto;   /* make overlay interactive when visible */
}

@media (prefers-reduced-motion: reduce) {
  .thumb .overlay { transition: none; }
}

On touch devices add a tiny toggle so a tap reveals the overlay (and a second tap follows links or dismisses it). Keep alt text for the image and use figcaption so screen readers can find the description; use the prefers-reduced-motion rule for accessibility. Finally, test in your target browsers and, if you must support very old engines, provide an immediate (no-fade) fallback so functionality remains consistent.

here is a quick flash version of what i am trying to make.

What I would do is set the z-index of the image to 0, and then create a second box with the background image as a semi transparent black, and then position it directly over the first image. Then give it a z-index of say 1, and then style it like this:

Example:
#box {
bakground-image: (url);
display:none;
}

#box a:hover {
dislpay:visible; or display:block;
}

thanks for the reply, but i came up with this working method.

html:

<div id="tut-img" class="imgbox">
			<img src="images/tut4.jpg" width="340px" class="tutorial-image">
<div class="details">
			<p>In this tutorial we will look at two different ways to create sketch materials that will make your 3D objects seem like 2D. We will also discuss how we can incorporate Sub Polygon Displacement and some other cool features along with that sketchy material.</p>	
			Running Time:: 9mins 20secs<br>
			Level::Intermediate
		</div>
		</div>

css:

.imgbox{
		float:left;
		width:340px;
		height:191px;
		overflow:hidden;
	}
	.details{
		width:320px;
		height:171px;
		padding:10px;
		background:#000;
		color:#fff;
		text-align:left;
	}
	#tut-img{position:relative;}
	#tut-img img{
		opacity:1
		-webkit-transition: opacity;
		-webkit-transition-timing-function: ease-out;
		-webkit-transition-duration: 500ms;
	}
	#tut-img .details{
		position:absolute;
		top:0;
		left:0;
		opacity: 0;
		-webkit-transition: opacity;
		-webkit-transition-timing-function: ease-out;
		-webkit-transition-duration: 500ms;
	}
	
	#tut-img .details:hover{
		opacity: .9;
		-webkit-transition: opacity;
		-webkit-transition-timing-function: ease-out;
		-webkit-transition-duration: 500ms;
	}

Very nice, however, your effect will not show up in firefox or IE, so if that doesn't matter, this will work nicely

actually it will work in firefox as that is my main browser, ie i know about, but am working on a workaround and will post it here when i have

well that was quick, as soon as i posted the last reply, i remembered how to do it in ie.

.imgbox{
		float:left;
		width:340px;
		height:191px;
		overflow:hidden;
	}
	.details{
		width:320px;
		height:171px;
		padding:10px;
		background:#000;
		color:#fff;
		text-align:left;
	}
	#tut-img{position:relative;}
	#tut-img img{
		opacity:1
		filter: alpha(opacity = 100);
		-webkit-transition: opacity;
		-webkit-transition-timing-function: ease-out;
		-webkit-transition-duration: 500ms;
	}
	#tut-img .details{
		position:absolute;
		top:0;
		left:0;
		opacity: 0;
		filter: alpha(opacity = 0);
		-webkit-transition: opacity;
		-webkit-transition-timing-function: ease-out;
		-webkit-transition-duration: 500ms;
	}
	
	#tut-img .details:hover{
		opacity: .9;
		filter: alpha(opacity = 90);
		-webkit-transition: opacity;
		-webkit-transition-timing-function: ease-out;
		-webkit-transition-duration: 500ms;
	}
filter: alpha(opacity = 100);

is all that was needed for opacity support in ie.


And yes i know that it will not fade in on firefox or ie (which i now realise is what you meant) but it doesnt matter.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.