简体   繁体   English

相对于页面的位置元素

[英]Position element relative to page

I have this element, and i want to position it to specific coordinates on the page. 我有这个元素,我想将其定位到页面上的特定坐标。 The problem is that it's inside another positioned element , so position:absolute places it relatively to this element, while i want it to be placed relatively to the page. 问题在于它位于另一个定位元素内 ,因此position:absolute相对于此元素放置它,而我希望将其相对于页面放置。

Is there some way i can place an element at specific coordinates on the page? 有什么办法可以将元素放置在页面上的特定坐标处?

You can see what i have on this page: http://bit.ly/NkfJk7 when you mouse over that yellow exclamation icon, i want the pink box to appear near that, but instead it appears in double that distance. 您可以在此页面上看到我所拥有的内容: http : //bit.ly/NkfJk7当您将鼠标悬停在该黄色感叹号图标上时,我希望粉红色的框出现在该位置附近,但它以两倍的距离出现。

I figured it out, i was doing it wrong. 我想通了,我做错了。

toolTip.style.left = button.offsetLeft + "px";
toolTip.style.top = button.offsetTop + "px";

No need to go absolute :) 不需要走绝对的:)

You can use position: fixed for this 您可以使用position: fixed为此position: fixed

https://developer.mozilla.org/en/CSS/position https://developer.mozilla.org/en/CSS/position

Fixed 固定

Do not leave space for the element. 不要为元素留出空间。 Instead, position it at a specified position relative to the screen's viewport and doesn't move when scrolled. 而是将其放置在相对于屏幕视口的指定位置,并且在滚动时不会移动。 When printing, position it at that fixed position on every page. 打印时,将其放置在每页上的该固定位置上。


EDIT: Disregard this answer. 编辑:忽略此答案。 Position-fixed positions relative to the screen, so it will follow around it the page scrolls. 相对于屏幕的固定位置,因此页面将围绕屏幕滚动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM