如何将 HTML 中的 100% 转换为 px

发布于 2024-08-12 00:17:19 字数 687 浏览 3 评论 0原文

我正在 GWT 中制作一个基于滑块的组件。

Parent : width = 100%
.-------------------------------------------------.
| .---------------------------------------------. |
| |     Child : width = X                       | |
| '---------------------------------------------' |
'-------------------------------------------------'

其中 X =(父级的宽度,以 px 为单位)-(一些基于运行时的计算);

我的代码显示:

int providedWidth = parentContainer.getOffsetWidth();

在 Firefox 中,我得到的宽度正确为(例如)345px 但在 IE6 中,无论大小如何,它都会不断地将宽度返回为 0。

从GWT的角度来看, Parent 是放置在 DockPanel 中的 AbsolutePanel(超级父级), 子项是一个 Horizo​​ntalPanel。

为了简洁起见,我没有在这里放置代码,有没有其他方法来获取宽度或 我做错了什么吗?

I am making a slider based component in GWT.

Parent : width = 100%
.-------------------------------------------------.
| .---------------------------------------------. |
| |     Child : width = X                       | |
| '---------------------------------------------' |
'-------------------------------------------------'

where X = (parent's width in px) - (some calculations based on runtime);

My code says:

int providedWidth = parentContainer.getOffsetWidth();

In Firefox, I get the width correctly as (say) 345px
But in IE6, it constantly returns the width as 0 no matter what size it is.

From GWT perspective,
Parent is an AbsolutePanel placed within a DockPanel (super parent),
Child is a a HorizontalPanel.

I haven't placed code here for brevity, is there any other way to get the width or am
I doing something wrong ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栀子花开つ 2024-08-19 00:17:20

只是一个大胆的猜测,但也许该元素在 IE6 中需要“布局”?你能给它style='zoom:1'吗?

Just a wild guess, but maybe the element needs "layout" in IE6? Can you give it style='zoom:1'?

娇俏 2024-08-19 00:17:20

在 IE 中,有时必须在 DeferredCommand 中获取大小信息,因为 IE 仅在事件线程完成后才进行布局。

In IE you sometimes have to get the size information in a DeferredCommand because IE only does the layout after the event thread is done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文