Making an svg image object clickable with onclick, avoiding absolute positioning

前端 未结 13 1171
轻奢々
轻奢々 2020-12-02 13:54

I have tried to change the images on my site from img to svg, changing img tags to embed and object tags. Bu

13条回答
  •  半阙折子戏
    2020-12-02 14:54

    Have you looked into using the CSS z-index property to make the container dev be "on top" of the svg? Because the div is (presumably) transparent, you will still see the image exactly as before.

    This, I believe, is the best-practice, non-hack, intended way of solving your problem. z-index is only useful for elements that have a position property of fixed, relative, or, as you've heard, absolute. However, you don't actually have to move the object.

    For example:

    
    

    For what it's worth, it would also be a little more elegant and safe to not use onClick at all, but instead to bind the click event using javascript. That's another issue altogether, though.

    提交回复
    热议问题