3

I have the following code:

<!DOCTYPE html> <html >
 <head> 
    <style type="text/css"> 
        .imgBox {background: url(lock75.png) no-repeat; } 
        .imgBox:hover {background: url(lock75light.png) no-repeat; } 
    </style> 
</head> 
<body> 
    <div style="width:200px; height:200px; border:1px solid;" class="imgBox"> </div> 
</body>
</html> 

My images are 75x75 and the problem occurs that when I hover over the border the image changes, I want when hovering over the image to change the image.

Note: I need a html construction similar to this one.

EDIT

I forgot to mention that I need the picture to be centralized above the other divs which I have not a certain space for the picture.

Thanks

6
  • reduced div width to 75px. Commented Oct 22, 2015 at 13:28
  • Similar to which one? Commented Oct 22, 2015 at 13:29
  • Not possible I have other content in the div except the image. Commented Oct 22, 2015 at 13:29
  • You have to create an extra div for images. Commented Oct 22, 2015 at 13:29
  • @AdamAzad A little more about your idea please? I have content (others divs buttons etc). Do you mean to place to other div above my divs with z-index or something? Commented Oct 22, 2015 at 13:34

2 Answers 2

1

You need to have a container that can hold both the background image and your content in the following structure (I know you asked for something similar to what you have posted, but it's not possible; well it is but it will involve CSS3 elements and jQuery)

Here's the setup

body {
    padding:10px;
}
.img-box {
    max-width:200px;
    width:100%;
    border:1px solid #ddd;
}
.img-box .img {
    width:200px;
    height:200px;
    background: url(https://unsplash.it/200/200/?image=876) no-repeat;
    border-bottom:1px solid #ddd;
}
.img-box .img:hover {
    background: url(https://unsplash.it/200/200/?image=876&blur) no-repeat;
}
p { margin:5px } 
<div class="img-box">
    <div class="img" ></div>
    <p>other content here</p>
</div>

Sign up to request clarification or add additional context in comments.

1 Comment

I forgot to mention that I need the picture to be centralized above the other divs which I have not a certain space for the picture.
1

I think you are searching for this:

.container {
    border:1px solid #000;
    display:inline-block;
    height:200px;
    width:200px;
}
.imgBox {
    background:url(http://placehold.it/100x100) no-repeat;
    height:75px;
    width:75px;
} 
.imgBox:hover {
    background:url(http://placehold.it/75x75) no-repeat;
}
<div class="container">
    <div class="imgBox"> </div> 
</div>

1 Comment

I forgot to mention that I need the picture to be centralized above the other divs which I have not a certain space for the picture.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.