Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Display new image on hover over <img>

Featured Replies

Having trouble with code

 

.latestwork:hover {

height:auto;

background-image : url(images/someImage.png);

 

Anyone know why this doesn't work?

I take it you've got the original (non-hover) image set as a background image as well? Rather than an in-page image?

 

If not, that would explain it lol.

 

If so, then can you post your html as well as the rest of the css :)

  • Author
I take it you've got the original (non-hover) image set as a background image as well? Rather than an in-page image?

 

If not, that would explain it lol.

 

If so, then can you post your html as well as the rest of the css :)

 

 

 

Hi Scott,

 

No, basically using this code

 

HTML

 

<div class="latestwork">

<img src="images/mainImage.png" alt="dummy image" width="275" height="216" />

</div>

 

 

CSS

 

.latestwork {

height:auto;

background-color:#999;

padding:5px;

margin-bottom:5px;

float:left;

clear:both;

width:auto;}

 

.latestwork:hover {

height:auto;

background-image : url(images/portmanGroupHover.png);

 

 

padding:5px;

margin-bottom:5px;

float:left;

clear:both;

width:auto;

 

}

The reason it wont work, is because the hover attribute is trying to apply a background image, which will be hidden by the existing image from within the html

 

Try setting the original image as a background image instead, see if that makes a difference

 

S

What scott said should work, however you would need to place a transparent img in the img tag (if theirs no image, it'll reveal the alt attribute, and cause aesthetic problems in some browsers). Alternatively, you could use a different tag (i.e div or span etc.)

 

You could also (this is what i would try) is wrapping the image in another tag, then on the img hover, set the visibility property, and have you background image on the wrapped element.

 

Like so.

 

<span class="hover"><img src="images/mainImage.png" alt="dummy image" width="275" height="216" /></span>

 

.latestwork {
height:auto;
background-color:#999;
padding:5px;
margin-bottom:5px;
float:left;
clear:both;
width:auto;}

.latestwork:hover {
height:auto;
visibility:hidden;
}

.hover{
display:block
background-image : url(images/portmanGroupHover.png); 
}

 

Not tested, but just an idea.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.