1
<style>
img { height: 100px; width: 100px; }
.hover img { display:none; }
.hover:hover img { display:block; }
</style>

<p>other text
</p>
<h1 class="hover">Test 1
<img src="ghost.jpg"/></h1>
<p>other text 
</p>

when i hover now it moves all the other text to display the image but i want the image to hover over the text and anything else on the page. not move the text to make room for the image. I know how to use jquery, and javascript but i didn't know what to use in this situation.

1
  • Have you tried setting your z-index on the image as well? That might solve it. Commented Nov 12, 2014 at 21:26

2 Answers 2

1

Position image absolutely without any top/bottom values:

img {
    height: 100px;
    width: 100px;
}
.hover img {
    display:none;
    position: absolute;
}
.hover:hover img {
    display:block;
}
<p>other text</p>
<h1 class="hover">Test 1
    <img src="http://lorempixel.com/100/100" />
</h1>
<p>other text</p>

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

1 Comment

thank you that's exactly what i needed! i just over thought it way to much lolz
0

Here is the answer of your question.

<style>
img { height: 100px; width: 100px; }
.hover img { display:none; }
.hover:hover img { display:block; }
</style>

<p>other text</p>
<h1 class="hover">Test 1
<img src="ghost.jpg"/></h1>
<p>other text 
</p>

See demo on JSDIDDLE

Comments

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.