0

(I really didn't know how to title this. Anyway!)

I have a couple of HTML buttons stacked vertically, which I consider the parent level. When you hover over a button, I have a div (or the child level) appear to the right of the button. To force the div to the right, I use position:relative;...

position:relative;
top:-25px;
left:200px;

but the buttons underneath the hovered button get pushed down like the div existed below the button.

How can I show the child div without the buttons being pushed down, while keeping the tops of the parent button and child div lined up?

Here's a jsfiddle as an example: http://jsfiddle.net/8Mbyu/

Matt Hansen
  • 424
  • 1
  • 6
  • 16

2 Answers2

1

Are you against using absolute positioning or is that ok? jsFiddle here.

.hiddenButtons { /*blue div*/
    display:none;
    background:#0af;
    width:100px;
    padding:5px;
    text-align:center;
    position:absolute;
    top:9px;
    left:210px;
}
dsgriffin
  • 66,495
  • 17
  • 137
  • 137
1

After a night of thinking about it, I figured I could use absolute positioning in conjunction with getting the position of the parent button via javascript:

In action: http://jsfiddle.net/8Mbyu/8/

.hiddenButtons { /*blue div*/
    display:none;
    background:#0af;
    width:100px;
    padding:5px;
    text-align:center;
    position:absolute;
    left:210px;
}

And the javascript:

$('.parentButton').hover(function () {
    $('.hiddenButtons').hide();
    var childID = '#' + this.id + 'Child';
    var rect = document.getElementById(this.id).getBoundingClientRect();
    var top = rect.top;
    $(childID).css("top", top+1);
    $(childID).show();
});

Thanks https://stackoverflow.com/a/11396681/1178486 !

I'm open to seeing cleaner solutions.

Community
  • 1
  • 1
Matt Hansen
  • 424
  • 1
  • 6
  • 16