954,591 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Element moves when hovering

Ok I made hover effect for group of five images-appearing border. But when I'm hovering the image some other two images are moving few pixels downward.

<div class="rel">
<img src="images/4wheel2.jpg" height="85" id="on"/>
<img src="images/4wheel2.jpg" height="85" id="on"/>
<img src="images/4wheel2.jpg" height="85" id="on"/>
<img src="images/4wheel2.jpg" height="85" id="on"/>
<img src="images/4wheel2.jpg" height="85" id="on"/>
</div>
<div class="ar">
<img src="images/arrowc.png"/>
</div>
<div class="at">
<img src="images/arrowc.png"/>
</div>

rel is class of div containing 5 images aligned horizontally; ar and at are classes containing identical arrow images; when I'm hovering the 4wheel2.jpg the arrow images are moving downwards.
The CSS code:

.rel{
	margin-left: 24%;
	margin-top: 40%;
	}
.ar{
	margin-top: -50%;
	margin-left: 45.5%;
	}
.at{
	margin-top: -3.2%;
	margin-left: 66.5%;
	}
#on:hover{
	border: 3px solid #2875DE;
	}


The hover makes ar and at classes move. Best regards

george61
Junior Poster in Training
59 posts since Jul 2010
Reputation Points: 10
Solved Threads: 6
 

It`s because you apply border to hovered element only. Add transparent border or 3px margin to non-hover state of #on. And you must not use ids for multiple elements if you want your page to be valid. Use classes instead.

Varnius
Newbie Poster
20 posts since Aug 2010
Reputation Points: 12
Solved Threads: 5
 

Thanks man. Now I'm having another problem.

<p class="cng" onclick="call()"><input type="file" id="file"/><b>Change background</b></p>


I want to replace this with

<a href="javascript:call()"><input type="file" id="file"/><b>Change background</b></a>


When I make the replacements the other elements of the page are moving few hundred pixels downward.This is the CSS

.cng{
	color: white;
	margin-top: -79.1%;
}

Any help will be greatly appreciated.

george61
Junior Poster in Training
59 posts since Jul 2010
Reputation Points: 10
Solved Threads: 6
 

Thanks man. Now I'm having another problem.

<p class="cng" onclick="call()"><input type="file" id="file"/><b>Change background</b></p>

I want to replace this with

<a href="javascript:call()"><input type="file" id="file"/><b>Change background</b></a>

When I make the replacements the other elements of the page are moving few hundred pixels downward.This is the CSS

.cng{
	color: white;
	margin-top: -79.1%;
}

Any help will be greatly appreciated.


Why did you put inside anchor? The main problem I can see here is bad(non-valid) markup.

Why not

<form action="">
   <p>
      <label>Change background</label>
      <input type="file" id="file" onclick="someFunction();"/>
   </p>
</form>
Varnius
Newbie Poster
20 posts since Aug 2010
Reputation Points: 12
Solved Threads: 5
 

float your anchor tag left. display block or inline-block as needed also. inputs shouldn't do inside of anchor tags, but if that's the way you want to do it, then this should fix it.

mpb2053
Newbie Poster
1 post since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: