Search code examples
htmlcsscenter

HTML position = center-10px


I am making an HTML website. I have an map as an background picture and I need a button to be on the map. Like this: This is how it should look like

But when I start scaling my site, this happens:enter image description here I know what is the problem: the position of the pictures is center-X px and center-Y px, not margin: 40% 0px 0px 20%. But how to do that? position: absolute; left: 50%-30px; top: 50%-83px doesn´t work.


Solution

  • You can use negative margins which has better support than calc().

    position: absolute;
    left: 50%;
    top: 50%;
    margin-top: -83px;
    margin-left: -30px;
    

    If you already have margins, you can just minus them from there. However, if they are defined as percentages or em's, then you're going to have to convert them accordingly.