Click here to Skip to main content
15,898,979 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi! I dont want image inside a div to move on mouse hover....
This is the code I am using but it is moving the image on mouse hover,how to avoid that?

CSS
<style type="text/css">

        .image {
            position: relative;
            width: 154px;
            height: 200px;
         }

        .image img {
            max-width: 150px;
            max-height: 150px;
            margin-left:100px;
            margin-right:100px;
            margin-top:100px;
            position: relative;

            }

        .hoverimage {
            position: absolute;
            top: 120px;
            left: 0;
            display: none;
           
        }

        .wrapper:hover .hoverimage {
            display: block;
            position:absolute;
            margin-left:123px;
            width:100px;
         }
        .main-wrapper:hover {
            border: 2px solid #7c97b4;
            width:auto;
            height:auto;
            display:block;
            width:300px;
            height:300px;
        }
        .main-wrapper {
           
            border-radius: 5px 5px 5px 5px;
            float: left;
            height: auto;
            margin-right: 1px !important;
            padding: 6px;
            position: absolute;
            
          }
     </style>


ASP.NET
</head>
<body>
    <form id="form1" runat="server">
       <div class="main-wrapper">
            <div class="wrapper">
            <div class="image">
                <img src="../Images/BlakeLively.jpg" alt="" />
                <a href="../Default.aspx">
                    <img class="hoverimage" src="../Images/buy-button.jpg" alt="" /></a>
            </div>
        </div>
           </div>
    </form>
Posted
Updated 18-Jun-13 4:41am
v2

Here are few problems:
1. You have a wrapper div inside main-wrapper div, but its class is not declared in style declaration.
2. Your image class has width 154px but the container class(.wrapper:hover .hoverimage ) has width of 100px
3. You don't have border for main-wrapper, but on mouse over you are adding border. Obviously it will take space and move the contents. One workaround is to add a border to it and change its color on mouse over or set its border color to the color of background(may be white).

I changed your code and checked, it worked for me. You also try this. But keep in mind, I used my images. I don't know what is the height and width of your images so change height and width of div's as per your requirement.

CSS
<style type="text/css">
        .image
        {
            position: relative;
            width: 154px;
            height: 200px;
            float: right;
        }
        .hoverimage
        {
            position: absolute;
            top: 120px;
            left: 0;
            display: none;
        }
        
        .wrapper
        {
            position: relative;
            margin-left: 123px;
            width: 160px;
            float: left;
        }
        .main-wrapper:hover
        {
            border: 2px solid #7c97b4;
            padding: 6px;
        }
        .main-wrapper
        {
            border-radius: 5px, 5px, 5px, 5px;
            float: left;
            height: auto;
            margin-right: 1px !important;
            padding: 6px;
            position: absolute;
            border: 2px solid Gray;
        }
    </style>


ASP.NET
<form id="form1" runat="server">
    <div class="main-wrapper">
        <div class="wrapper">
            <div class="image">
                <img src="images/template10.jpg" alt="" />
                <a href="Default.aspx">
                    <img class="hoverimage" src="images/check48.png" alt="" /></a>
            </div>
        </div>
    </div>
    </form>
 
Share this answer
 
v3
Comments
El Dev 18-Jun-13 10:58am    
yes Zafar,I understand but when I am applying the style to the div...it is like the div is moving,I dont know how to explain that.But the purpose is to wrapper the image inside that div and this element must be fixed nothing need to be like moving what.Please test this you will see that.The css code you are comment out is where is the problem.I need that border style.Thanks!
Zafar Sultan 18-Jun-13 11:21am    
Updated my solution. Check if it works.
El Dev 18-Jun-13 11:26am    
I've tried your code but nothing changed,still the picture is moving somehow.
Zafar Sultan 18-Jun-13 11:54am    
Please check my updated solution.
El Dev 18-Jun-13 12:07pm    
Thanks Zafar sultan!it works...
Normally, nothing really moves on mouse hover. If it moves, it means that you have added some code to move it. Remove that code if you don't need motion. :-)

—SA
 
Share this answer
 
Comments
El Dev 18-Jun-13 10:40am    
Did you check my code,it is like moving somehow when I mouse hove I want it to be fixed.The image inside.
Sergey Alexandrovich Kryukov 18-Jun-13 12:00pm    
Yes I did. You are not moving anything in this part of code; if something moves, it's somewhere else. Where?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900