Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
Blindside the Borg queen: Image with overlaying element that is absolute positioned above the same area of the image when the image rescales

Sorry if this is not the right way to do it, please feel free to suggest other solutions. I don't care what the text or the blindfolding element is as long as it servers the purpose. Maybe it is possible to do this with an svg but it is way too advanced for me.
I am trying to create a page showing an image with a certain area covered so that the reader can't see it. Here is my code so far. Not sure how to calculate/recalculate the position of that element based on the new position and size of the picture when the browser window resizes https://jsfiddle.net/xay5u78s/

    <html lang="en">
<head>
  <title>Bootstrap Responsive image example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
  </head>
  <body>

    <div >
        <div >
            <img src="https://upload.wikimedia.org/wikipedia/en/b/bc/Borg_Queen_2372.jpg" class="img-fluid"  style="width:30%" alt="image">
            <div class="position-absolute" style="height:30px; background-color: white; top: 25%;left: 13%;"> Covered covered </div>
        </div>
        
    </div>

</body>  
</html>

Desired effect enter image description here enter image description here

Updated fiddle with the solution as suggested by @quentin
https://jsfiddle.net/xay5u78s/1/

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Absolutely positioned elements are positioned with respect to the edges of the nearest ancestor element that is positioned (meaning "Has position: anything-but-static").

So set the containing div to position: relative and give it the same dimensions as the image.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!