Cross-browser method for getting width and height of a DIV?

前提是你 提交于 2019-12-06 12:31:23
cletus

It sounds to me that you need to add a DOCTYPE to your page to force IE into "standards compliant" rather than "quirks" mode. See Quirks mode and strict mode.

Also see width():

and outerWidth():

I don't know whether this helps, but the following fragment will set the height of an inner element so that it completely fills the available space. The inner element (e) can be nested at any depth inside a reference element (r) which has a set height. The fragment takes into account the heights of all siblings between e and r. Both parameters can be passed either as DOM elements or JQuery objects.


var fit_v = function ( e, r, no_set ){
    if (!e.jquery) e = $(e);
    if (!r.jquery) r = $(r);
    var h, s, b = 0, d = 0;
    for (var i = 0; i < r[0].childNodes.length; i++){
      s = $(r[0].childNodes[i])
      d += s.outerHeight();
      d += Math.max(b,parseInt(s.css('margin-top')));
      b = parseInt(s.css('margin-bottom')); 
    } 
    d += b;
    h = r.height() - d;
    if (!no_set) e.height(h); 
    return h;
  };
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!