【问题标题】:How can I attach an object to a fixed location on an image?如何将对象附加到图像上的固定位置?
【发布时间】:2014-09-05 05:40:39
【问题描述】:

到目前为止,我只知道如何将对象放置到具有页面坐标的固定位置。
这是问题:

当我向上/向下/向左/向右移动图像时(对象是图像上可以单击的点),这些点将停留在旧位置。

那么有没有办法从图像中给它们坐标?然后我可以移动 img 并且这些点会保持在原来的位置,不是吗?

这些是我的观点 (CSS):

div.point {
    border-radius: 50%;
    width: 28px;
    height: 28px;
    background: #7ab51d;
    border: 3px solid white;
    position: fixed;
    z-index:1000;
    cursor: pointer;
}

我如何定位它们:

<div id="Restroom_Water" class="point" style="top:380px;left:1000px;" onmouseover="$('#Restroom_text_Water').show();" onmouseout="$('#Restroom_text_Water').hide();"></div>

【问题讨论】:

    标签: html css image position


    【解决方案1】:

    改变位置属性:

    div.point{
        position: relative;
    }
    

    这意味着点对象的像素位置是相对于父容器(在本例中是您的图像)。

    This article 很好地完成了定位。

    【讨论】:

    • 所以我需要把点和img放在同一个容器里吗?
    • 正确。该容器是固定的,但点是相对的。这是一个小提琴:jsfiddle.net/gfuh2pf0
    猜你喜欢
    • 2017-04-11
    • 1970-01-01
    • 2011-12-07
    • 1970-01-01
    • 2011-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    相关资源
    最近更新 更多