jQuery的垂直对齐2的div [英] jquery vertical align 2 divs

查看:83
本文介绍了jQuery的垂直对齐2的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想要实现



我有一个流体提示和一个按钮。它们的宽度是由文本和div填充来确定。该文本可以改变。这说怎么会是可能的垂直通过jQuery调整呢?

I have a fluid tooltip and a button. Their width is determined by the text and div padding. The text can vary. That said how would it be possible to vertically align them via Jquery?

我想使用jQuery的原因是为了避免使用表格和过多的HTML。

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

我试过的宽度()函数​​,但它并没有给出确切的宽度。我想,一个人应该得到填充呢?

I tried the width() function but it doesn't give the exact width. I suppose one should get the padding too?

最后,我最不善于用数字。我不知道什么公式可以使用,但我怀疑,也许这两个分格宽度2,不管怎样中心的中段?

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

编辑:点击按钮时,提示出现,是绝对不干扰/推其他的div

When clicking the button, the tooltip appears and is absolute not to interfere/push other divs.

编辑:正在进行jsfiddle.net/Aezb6工作

Work in progress jsfiddle.net/Aezb6

推荐答案

获取calloutdiv //宽度

Get the width of the calloutdiv//

widthCallout = $('#calloutdivWidth'); //这是动态的,

由宽度按钮中的哪一个不断分裂这个。

divide this by width of push button which is constant.

被甩:

left= widthCallout/pushbuttonwidth

您可以玩弄以下属性来值+或 - 它给你确切的中心:

you can play around with paddingLeft value + or - which gives you exactly the center :

这篇关于jQuery的垂直对齐2的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆