I’m using an image as a background in a div. The image is positioned as center, no-repeat and has cover as size, and will therefore show different sections when viewed on different screens/devices. Nothing strange about that.
I would like to position some markers on the image, and that those markers have absolute positions relative to the background image, regardless of the screen/device.
Is this even possible?
I’ve tried to position the markers as absolute and with percent positions but that, needless to say, didn’t work.
<DIV style="width:100%;height:100vh;background-image: url('temp/bg.jpg'); background-position: center;background-repeat: no-repeat; background-size: cover;">
<DIV style="position:absolute;top:82%;left:15%">Marker</DIV>
</DIV>
3
Answers
You need to define your image container as relative and the marker as absolute
Don’t use a background image, they do not resize the way you think in proportion to the screen.
Use an actual inline image in a container and absolute position your elements in relation to that container in percentage values.
Something like this.