user34537
user34537

Reputation:

css position relative unwanted extra space

I'm getting a strange effect in my css. When i mouse over a box it moves the next box by 32 pixels. Why? I assume its because of the checkbox but I shifted it left by 32px.

Demo

html:

<div class="Z"> <a href="http://google.com"><img src="http://25.media.tumblr.com/tumblr_m9p3n1vJmZ1rexr16o1_400.jpg" class="A"/><img src="http://suvendugiri.files.wordpress.com/2012/02/checkbox.png" class="B"/></a>
    <a
    href="http://google.com">
        <img src="http://25.media.tumblr.com/tumblr_m9p3n1vJmZ1rexr16o1_400.jpg"
        class="A" />
        <img src="http://suvendugiri.files.wordpress.com/2012/02/checkbox.png"
        class="B" />
        </a>
</div>

css:

/*.B { display: none; }/**/
 a:hover .B {
    display:inline-block;
}
.B {
    display:none;
    width: 32px;
    position: relative;
    left:-32px;
    vertical-align:top;
}
/
/*/
//.Z > * {vertical-align:top; }

JS (unneeded):

$('.B').click(function () {
    alert('a');
    return false;
});

Upvotes: 1

Views: 261

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191819

left: -32px does not move the element's box model, only where it is displayed. I would handle this differently:

a {
    position: relative;
}
 a:hover .B {
     display: inline;
}
.B {
    display:none;
    width: 32px;
    position: absolute;
    right: 0;
}

http://jsfiddle.net/NPXFZ/1/

Upvotes: 2

Related Questions