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

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

问题描述

这正是我想要实现的







我有一个流畅的工具提示和一个按钮。它们的宽度由文本和div填充决定。文本可以有所不同。这说明如何通过Jquery垂直对齐它们?



我想使用jquery的原因是避免使用表和过多的HTML。



我尝试了width()函数,但它没有给出确切的宽度。我想应该得到填充也?



最后,我是可怕的数字..我不知道什么公式可以使用,但我怀疑可能划分两div宽度为2,并以某种方式居中中点?



编辑:当点击按钮时,工具提示出现,绝对不会干扰/推送其他div。

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

解决方案

calloutdiv //



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



用按钮的宽度除以常数。



左侧:

  left = widthCallout / pushbuttonwidth 

可以用paddingLeft值+或 - 这给你的中心:


This is what I'm trying to achieve


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?

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?

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?

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

EDIT: Work in progress jsfiddle.net/Aezb6

解决方案

Get the width of the calloutdiv//

widthCallout=$('#calloutdivWidth'); // this is dynamic

divide this by width of push button which is constant.

get left :

left= widthCallout/pushbuttonwidth

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

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

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