Arrange pictures on top of one another with accuracy in Bootstrap

Looking for a way to stack two images precisely on top of each other.

However, the top image (the circle) keeps moving around unpredictably.

Both images are within a responsive grid setup and the base image should always remain centered.

Let's say we want to focus on the hip for instance. Check out the images: https://i.sstatic.net/6FPpn.jpg

When I resize the page, the right image shifts down as intended, but the circle ends up elsewhere (like on the hand). Take a look at the images here: https://i.sstatic.net/4iOmL.jpg

This is the code I'm using:

/* No-margins Class Rules */

.row.no-gutters {
  margin-right: 0;
  margin-left: 0;
}

.row.no-gutters>[class^="col-"],
.row.no-gutters>[class*=" col-"] {
  padding-right: 0;
  padding-left: 0;
}


/* Centers content */

.centered-img {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 100px;
}

.img-container {
  background-color: yellow;
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
}

.test {
  position: absolute;
  transform: translate(-50%, -50%);
  left: 100px;
}
<!doctype html>
<html lang="{{ app()->getLocale() }}">

<head>
</head>

<body>
  <div class="container">
    <!-- global canvas -->
    <div class="row no-gutters">

      <div class="col-sm">
        <div class="centered-img">

          <img src="./images/fssFront.png" class="img-fluid" alt="Responsive image">
          <img src="./images/circle.png" class="test" alt="Responsive image">

        </div>
      </div>

      <div class="col-sm">
        <div class="centered-img">
          <img src="./images/fssBack.png" class="img-fluid" alt="Responsive image">
        </div>
      </div>

    </div>
  </div>
  <!-- global canvas -->
</body>

</html>

Any suggestions on how to keep the red circle consistently aligned with the man regardless of page size changes?

Your help is greatly appreciated in advance.

Answer №1

It appears that your two images may be utilizing different reference points to establish their positions. Moreover, in order for them to adapt responsively, all measurements need to be represented in percentages.

The initial issue lies in the fact that by applying position:absolute to your circle element, you are altering its reference point to the nearest container above it with a position:relative or position:absolute declaration. In this scenario, there is no such container present, causing the circle to default to using the entire document as its reference point. With the circle referencing the page and the image referencing its parent, resizing will result in misalignment due to anchoring at distinct points.

In addition, since responsiveness is desired, all positional attributes should be specified in %. Using left:100px on your circle will not adjust properly during resizing. Consider either determining the precise location through the transform property or converting the left value into a percentage.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Vanilla JS solution for closing dropdown button

Is there a way to close the dropdown button using Vanilla JS? I have successfully implemented a method to open the dropdown button, but am struggling to find a way to close it. I would like to maintain the for loop for functionality but need guidance on ho ...

ng-switch is failing to function in specific instances

I'm currently constructing a login module using AngularJS. Below is the code snippet: For the main page HTML: <div id='main' ng-controller='LoginController'> <div class='yomate-header'> <div c ...

Animating circles with CSS to display percentages

Currently, I have a circle displaying text in the center as shown in this fiddle (JSFIDDLE http://jsfiddle.net/874jgh4v/2/). Now, my requirements are: I want to animate the outer white border based on a percentage. For example, if the percentage is 50% ...

AngularJS provides a convenient way to vertically populate data cells in a table

Looking to vertically populate data cells with an array in this HTML table. Below is a basic HTML table structure: <table> <th>Name</th> <th>Value</th> </table> Current table data: Name Value X Y Desired output: ...

Having trouble displaying images in Express JS

Here are the lines of code that I wrote in Express: res.write("The current temperature is "+temp+". "); res.write("Weather is currently "+weatherDes); res.write("<img src=" +imageURL+ ">"); res.send() ...

What is the method for adjusting a "column" of spans to align with the right side?

I need help with aligning the first "column" of spans to the right using only spans instead of divs. Here is the link to my fiddle: http://jsfiddle.net/f6a01v9a/1/ <h4>How to align first "column" of spans to the right?:</h4> <span style=" ...

The circular loader in reactstrap Spinner is not displaying as expected

I am attempting to display a loader using the reactstrap (v^7.1.0) Spinner component, but nothing is appearing on the screen. When I inspect the page in Chrome, it seems that the CSS for Spinner is not present. https://i.sstatic.net/uVsRn.png Does anyone ...

Navigating Checkbox in Active Choice Reactive Reference Parameter on Jenkins

I attempted to configure an active choice reactive reference parameter using the instructions outlined in this guide: Here is the code for the reactive reference parameter: service_tier_map = [ "web": [ ["service_name": "use ...

Ensuring uniform column heights with Semantic UI

I came across the "equal height" classes in Semantic UI, but I'm having trouble applying them to inner divs, like the "ui segment" for example. More details can be found here. Take a look at my screenshots below: https://i.sstatic.net/o9kwC.png < ...

Leveraging the power of javascript to include content before and after

I am looking to understand how I can insert an HTML element before and after certain elements. For example, let's say we have the following code in a real file: <ul class="abcd" id="abcd></ul> How can I display it like this using JavaScr ...

When using HTML select, text alignment may not be centered properly in the Chrome

Recently, I encountered an issue where the text in select options is not centered in Chrome. Interestingly, using text-align: center on the select element works perfectly fine on Firefox, but fails to do so on Chrome. I haven't had the chance to test ...

What is hindering me from fetching the information stored in my json file?

Currently, I am delving into learning AngularJS by working on a simple webpage for a company. This page will showcase products that are fetched from a json file. Following a tutorial from the AngularJS website, which covers the exact task I aim to achieve, ...

HTML/CSS - Enhances user experience by zooming in on select tag when tapped on mobile devices

I am experiencing an issue with a select menu on mobile devices. Whenever I tap on the menu, it seems to zoom in slightly. Is there a particular -webkit property causing this behavior? How can I prevent the screen from zooming when I tap on the select me ...

Delaying Bootstrap 3 Carousel Captions

Website: Issue: I am attempting to integrate the javascript slide.bs.carousel into my code in such a way that the caption appears a few seconds after the image loads in the slideshow. I have inserted the code for 'slide.bs.carousel' within a scr ...

stopping a float-left div from being pushed down by a table

I am facing an issue with two float:left divs that are supposed to stack left-to-right. One div is a fixed width left nav, while the other should span the remaining width of the browser. The problem arises when there is a table in the second div with multi ...

Creating a hierarchical structure in HTML to represent a JSON object as a tree: techniques and best practices

I need help with displaying a nested JSON object that shows a one to many relationship between a parent node and its children in an organizational chart format using HTML. I have looked into utilizing Google Charts for this purpose, but I am unsure if it a ...

Discover the ultimate strategy to achieve optimal performance with the wheel

How can I dynamically obtain the changing top position when a user moves their mouse over an element? I want to perform some checks whenever the user scrolls up, so I tried this code: HostListener('window:wheel', ['$event']) onWindowS ...

Restricting the amount of text that can be applied to an HTML5 canvas

Currently, I am in the process of developing a tree structure engine using an HTML5 canvas. In this engine, each tree node is connected to a database and has a unique name along with various other values. To represent these nodes visually, I have assigned ...

HTML - one div's child element takes precedence over another div

My HTML page features two consecutive divs. The first div contains a child span that has a relative position, causing it to overlap the second div. I have implemented click events for both divs. However, when I click on the span that overlaps the second d ...

Refine the pandas Dataframe with a filter on a JavaScript-enabled website

I recently inherited a large software project using Python/Flask on the backend and HTML/Javascript on the frontend. I'm now looking to add some interactivity to one of the websites. I have successfully passed a dataframe to the webpage and can displa ...