How do I retrieve an HTML element's actual width and height?

前端 未结 14 1823
后悔当初
后悔当初 2020-11-22 02:29

Suppose that I have a

that I wish to center in the browser\'s display (viewport). To do so, I need to calculate the width and height of the &l
14条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 02:43

    You only need to calculate it for IE7 and older (and only if your content doesn't have fixed size). I suggest using HTML conditional comments to limit hack to old IEs that don't support CSS2. For all other browsers use this:

    
    
    test
    test

    This is the perfect solution. It centers

    of any size, and shrink-wraps it to size of its content.

提交回复
热议问题