Can't get right width or outerWidth of <label> element

橙三吉。 提交于 2019-12-13 00:08:26

问题


simply can not understand this problem I have - I need the .outerWidth() of a <label> element, but it keeps returning a value that is different from the one I can read out of my firebug?

.outerHeight works just fine though.

SOLVED: Note to self: custom fonts and calculations of width does not work all that well, lol


回答1:


When you use custom fonts, you must use the .outerHeight method on $(window).load(function(){}, not $(document).ready(function(){}. The first case waits for all the elements of the window to be loaded (including the custom font and the image) otherwise in the second case it is ready before the custom element is loaded and it not know the dimension of it.




回答2:


Maybe you need .outerWidth(true) wich includes the margin of the element.

http://api.jquery.com/outerWidth/ for more specific information on the outerWidth function.




回答3:


SOLUTION/PROBLEM: I used custom fonts - must be a workaround though - dont have time to find it yet :-D



来源:https://stackoverflow.com/questions/5539602/cant-get-right-width-or-outerwidth-of-label-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!