Answer the question
In order to leave comments, you need to log in
For fixing labels on an adaptive image?
Hello. There is an image that proportionally "stretches" depending on the width of the browser. Position: absolute labels are placed at the top. It turns out I can put them down correctly only for a fixed image size, otherwise they move apart. How can you dodge and make sure that they at least approximately remain in their places?
Answer the question
In order to leave comments, you need to log in
We take the original size of the image, the position and dimensions of the label.
And based on them, we determine what percentage is ...
Well, we put these values in place of the fixed ones.
/*--Было--*/
.image{
width: 800px;
height: 400px;
}
.metka{
left: 20px;
top: 40px;
width: 10px;
height: 10px;
}
/*--Стало--*/
.image{
width: 100%;
height: auto;
}
.metka{
left: 2.5%;
top: 10%;
width: 1.25%;
height: 2.5%;
}
<div style="position:relative;height:auto;">
<img class="image">
<span class="metka"></span>
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question