Dynamic scaling and positioning of multiple images in relation to each other using CSS

I am currently working on layering images over a large logo and making sure it remains responsive. I want the overlaid images to maintain their position on the logo even when the browser window size is reduced.

Here is what my current browser display looks like (I aim for the images to stay in place while resizing): current browser view

Below is the code I have developed so far:

#frame {
    display: inline-flex;
    justify-content: center;
    width: 100%;
}

#logo-canvas {
    width: 60%;
    margin-left: auto;
    margin-right: auto;
}

.parent-photo {
    position: relative;
}

#child-photo1 {
    width: 4rem;
    height: 4rem;
    border-radius: 50%;
    position: absolute;
    left: 1rem;
    top: 1rem;

}

#child-photo2 {
    width: 4rem;
    height: 4rem;
    border-radius: 50%;
    position: absolute;
    left: 2rem;
    top: 2rem;

}
<section>
  <div id="frame" class="parent-photo">
    <img id="logo-canvas"src="assets/images/salmon-logo.png" alt="Wild Logo Shape">
      <!--<div id="parent-photo"> -->
    <img id="child-photo1" src="assets/images/Lorem-Ipsum-alternatives.png" alt="Photo 1">
    <img id="child-photo2" src="assets/images/Lorem-Ipsum-alternatives.png" alt="Photo 2">
      <!--</div> -->
  </div>
</section>

Although I initially thought the parent/child relationship with the position attribute would work, I seem to be stuck (possibly due to the flex property interfering). As a beginner, any assistance would be greatly appreciated!

Thank you in advance to anyone who can provide guidance! :)

Answer №1

From personal experience, I've found it quite challenging to achieve the desired layout that works seamlessly across all screen sizes.

However, if you're up for experimenting, consider utilizing vw units to position and scale the child images dynamically based on viewport dimensions.

You can start by trying out the following CSS code:

#child-photo1 {
    width: 5.5vw;
    height: 5.5vw;
    border-radius: 50%;
    position: absolute;
    left: 1.375vw;
    top: 1.375vw;
}

#child-photo2 {
    width: 5.5vw;
    height: 5.5vw;
    border-radius: 50%;
    position: absolute;
    left: 2.75vw;
    top: 2.75vw;
} 

Keep in mind that the images may appear too small on mobile devices and too large on desktop screens. In such cases, you might need to set max-width, max-height, min-width, or min-height properties accordingly.

Answer №2

한글로 작성합니다. 원하는 이미지들을 png 형식으로 동일한 크기로 만든 후, 부모 태그도 같은 크기로 설정하고 position을 relative로 지정합니다. 자식 요소에 있는 해당 이미지들을 absolute로 설정하고 max-width:100%로 지정합니다. 마지막으로 해당 이미지를 top, left 등의 퍼센트 값으로 조정해 줍니다.

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

Unexpected behavior with first-child selector in a simple CSS code

It seemed so clear to me, but it turns out I was mistaken. Check out this link $('p:first-child').css({color:'red'}); The color of all text is not being altered. <div class="post text"> <a href="#">this is a url</a> ...

What is the best way to ensure that my image completely occupies the div?

I am facing a challenge in creating a hero image that would completely fill the div on my webpage. Despite setting the width and height to 100%, the image seems to only occupy half of the space. Check out the CSS and HTML code snippet here. div.hero{ ...

What is the reason border property does not transition effectively?

I am trying to remove the border property after a certain period of time (1 second) and make it smooth. Here is what I have attempted: var elem = $('div').css({'border-top':'6px solid #FC9A24', 'border-le ...

Change to a dark theme using React hooks in typescript

Hello, I am new to React and English is not my first language, so please excuse any mistakes. I have been trying to enable a dark mode feature on my website. Most examples I have found involve toggling between dark and light modes where you need to specify ...

Strange Behavior of HTML5 Audio Elements

I'm currently in the process of designing a shop website with a nostalgic Windows98 theme. On the product's page, I want to include a preview of audio. Here is the CSS code that I have used for the HTML5 audio element: audio::-webkit-media-contr ...

Ways to disable the ability to close a bootstrap modal by pressing the backspace key

How can I enable the backspace button in a Bootstrap Modal form for textboxes and textareas? $('body').keydown(function (e) { if ($('#myModal').is(':visible')) { if (e.keyCode == 8) { retu ...

Positioning a div with a set size to the right while allowing a div with a variable width to the left

Even though I achieved the desired outcome in this example (http://jsfiddle.net/jcx3X/40/), I am intrigued by the reasons why this other scenario (http://jsfiddle.net/jcx3X/41/) does not work. What is the significance of the div being floated first in th ...

I am experiencing issues with the loading of CSS and JavaScript files in my recently created Laravel project

Recently, I received a Laravel project and successfully downloaded its configuration to get it up and running using php artisan serve. Upon attempting to access the project through localhost:8000, only the HTML content is displayed without any styling fro ...

Difficulty adjusting image size in "layouts with overflowing images on cards."

I have encountered an issue with resizing images on my browser using a card-based layout that I found on codepen. The strange thing is, the image resizing works perfectly fine on codepen itself, but when I try to implement the same HTML and stylesheet on m ...

Is your toggleclass button suffering from technical difficulties?

Why am I having trouble toggling the box with the button? I want it to maintain its current functionality and also toggle the box as well. Check out my JS fiddle for reference. Here's my code snippet: $(function timelinetiles() { $('.timeline ...

Adjust the input width dynamically in Angular

Looking to dynamically adjust the width of an input field and ensure that the suffix "meters (m)" sticks close to the entered number. Additionally, I want to pass a specific value to the input using `value="something"`, which then should expand the input w ...

Is it better to use multiple external style sheets?

Hello! I am looking to implement a pop-up login screen by integrating downloaded code. The issue I am facing is that the CSS file that accompanies it clashes with my current one. Is there a way to have a specific style sheet only affect certain div tags, ...

An HTML attribute with a blank value will not display the equals sign operator

jQuery can be used like this: $select.append('<option value="">All</option>'); This code appears to insert the element in HTML as follows: <option value>All</option> However, what is intended is to append the elemen ...

Breaking apart a pipe-separated text and sending it through a JavaScript function

CSS: <div class="pageEdit" value="Update|1234567|CLOTHES=5678~-9876543?|5678"> <a href="https://host:controller">Update</a> </div> Trying to retrieve the data within the div and pass it into a JavaScr ...

Error: JavaScript Framework (JSF) application experiencing issues with jQuery functionality

I am a beginner when it comes to jQuery. In my Netbeans project, I have the jquery-1.7.2.js file where all HTML files are stored. Currently, I am working on creating a JSF 2.0 project. Below is the code snippet I am using: <?xml version='1.0&apo ...

The fixed table header is misaligned with the body columns' width

I was looking for a way to add a vertical scrollbar to my table, and I ended up wrapping the entire table in a div. The result was that the table head was fixed in position. Is there a simpler method to include a scrollbar in a table without affecting the ...

The left and right edges are not extending across the entire screen

Can anyone help me determine if this is a duplicate issue? I'm unsure why my left and right borders are not extending the full width of the screen. The website in question is ojs.monojitbanerjee.co.cc Here is the structure: <body> <div id= ...

Each time the web animation is utilized, it gets faster and faster

As part of an assignment, I am working on creating an interactive book that can be controlled by the arrow keys and smoothly comes to a stop when no key is being pressed. However, I have noticed that with each arrow key press, the animation speeds up. Bel ...

Utilizing a jQuery click event to modify the placement of a table

I have a request regarding the tables within the #middlebox. I would like to be able to rearrange the table positions by clicking on the list items. For instance, if the current order of the tables is starter -> soup -> seafood, clicking on the #seaf ...

My element's padding being overlooked by Tailwind CSS

In the process of developing a comment/response mechanism through MPTT, I am utilizing indentation to clearly designate replies and their respective levels. The comment.level attribute is being employed to establish the padding value. Consequently, a comm ...