开发者

Weird width reported in DOM (0, when element has width)

I think the image explains what's going on pretty well. I know this happens with images that haven't loaded yet.. and the width of this element is changing, but the functions I need the width with are being called and extracting the width af开发者_JAVA百科terwards, and usually Web Inspector updates itself, so... what could be happening here? (I'm trying to apply the width of one element to another, and because of the 0 reported width the second element is invisible. It's only doing this on some of the elements, though.

These are inline elements, so perhaps that's the reason? But clearly someone is generating a width somewhere, and it is working with other inline elements with the same js but different css.

Weird width reported in DOM (0, when element has width)


Elements with "display: inline" such as <span>'s or <a>'s do not use or have a width style property. If you set the element to "display: inline-block" it will use a width style property.

element.offsetWidth will give you a proper width, but the "computed style" of a inline element will always be 0. Inline elements have an automatic width, so the style applied has no effect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜