jQuery:以像素为单位获取DIV的确切位置,而不是返回“auto”作为结果

时间:2012-05-05 15:36:00

标签: jquery position

假设我有div 高度和宽度不等float:left;

当我使用.css("");获取他们的位置(左和右)时,

"auto"总会成为结果。

获取相对于容器的确切数字(左和右)的任何方法(以像素为单位) 的 position:absolute;

div有可能在我使用float:left;时开始新行,并且它们的宽度和高度无法确定。

1 个答案:

答案 0 :(得分:4)

jQuery有两种位置方法,一种是相对于文档,另一种是相对于容器。

Relative to container (position)

Relative to document (offset)

请注意,位置相对于偏移父项,因此您可能必须应用position:relative to container elements。