Jquery vertical align 2 divs

This is what I'm trying to achieve.

alt text

I have a current tooltip and button. Their width is determined by the text and padding of the div. The text may vary. However, how could you vertically align them through jQuery?

I want to use jquery to avoid using tables and excessive HTML.

I tried the width () function but did not give the exact width. I suppose you also need to get a residence permit?

Finally, I'm terrible with numbers. I'm not sure which formula can be used, but I suspect that maybe dividing both div widths by 2 and somehow centering the middle?

EDIT: when a button is pressed, a tooltip appears and absolutely does not interfere / click on other divs.

EDIT: Work in the jsfiddle.net/Aezb6 process

+3
3

calloutdiv//

widthCallout=$('#calloutdivWidth');//

.

:

left= widthCallout/pushbuttonwidth

paddingLeft + - :

+2

. :

var item = $(".tooltip");
var container = $("#container");

var position = item.position();

var mytop = position.top - container.height() + $(document).scrollTop();
var myleft = position.left - container.width() + $(document).scrollLeft();

// Correct relative coordinates for IE and WebKIT
if($.browser.msie || $.browser.webkit){
    mytop = position.top - container.height();
    myleft = position.left - container.width();
}

container.offset({top: mytop, left: myleft});

+1

Source: https://habr.com/ru/post/1776110/


All Articles