顶部和左侧对自定义按钮的位置没有影响

发布于 2024-11-25 14:20:31 字数 404 浏览 2 评论 0原文

对于我正在开发的项目,我需要制作一个可以拖放的自定义按钮,然后保存它的位置,以便可以打开一个单独的窗口,并且该按钮位于与保存时相同的位置。现在的问题是顶部和左侧,这应该是更改/保存按钮位置的两个主要属性。我在 CSS 中为按钮指定了这两个属性,但是当我使用 firebug 时, left 和 top 都没有分配给它们的值。此外,我还在 CSS 中指定了按钮的高度和宽度。我的按钮具有正确的尺寸,但其高度和宽度值均为空。有谁知道为什么会发生这两种情况?

我还尝试在 javascript 中设置值,这给了 top 和 left 一个值,但对按钮的定位没有影响。我不明白的另一件事是,更改按钮 marginLeft 和 marginTop 会影响按钮位置,但这不是定位按钮的合法选项,因为我需要让按钮彼此靠近,如果它们有,这将不起作用一个边距。那么顶部和左侧不会影响按钮的位置吗?

For a project I'm working on, I need to make a custom button that can be dragged and dropped and then have it's position saved so that a separate window can be opened with the button in the same position as it was saved at. The issue right now is top and left, which are supposed to be the 2 main attributes in changing/saving a buttons location. I specify both attributes in CSS for the button, but when I use firebug, neither left nor top have a value assigned to them. Furthermore, I specify the height and width of the button in the CSS as well. My button has the proper dimensions but its height and width values are both empty. Does anyone know why either of these scenarios could happen?

I also tried setting the values in javascript, which gave top and left a value but had no effect on the button's positioning. The other thing I don't get is that changing the buttons marginLeft and marginTop affects the buttons position, but this is not a legitimate option for positioning the button because i will need to have buttons close to each other, which wont work if they have a margin. So is there a reason that top and left wouldn't have an affect on a button's positioning?

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

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

发布评论

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

评论(1

缱倦旧时光 2024-12-02 14:20:31

您需要使用 position:relative;position:absolute;position:fixed;。您还需要确保其 displayinline-blockblock 以使宽度和高度正常工作。

You need to use position:relative;, position:absolute;, or position:fixed;. You also need to make sure its display is inline-block or block for width and height to work.

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