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

Is it feasible to place an ordered list within a table row <tr>?

Below is a code snippet demonstrating how to create an ordered list using JavaScript: Here is the JavaScript code: <script type="text/javascript"> $(document).ready(function() { $("ul").each(function() { $(this).find("li").each(functio ...

The landscape orientation media query does not adhere to the specified maximum width

I am currently working on creating a mobile landscape design for a website specifically tailored for iPhone SE and iPhone 12. In the process, I encountered an issue that caught my attention: Within two different breakpoints, I made adjustments to the top ...

Design a CSS floating div with a captivating bubble effect

My current setup includes a DIV element styled as follows: <div class="modal"></div> .modal { position: fixed; z-index: 999999; right: 310px; top: 67px; width: 431.6px; height: 550px; border-radius: 25px; box-s ...

Using CSS to Showcase the Art Gallery Page

This is my unique gallery display: https://i.stack.imgur.com/RddD8.png Here is the look I am going for https://i.stack.imgur.com/kuOye.png I want to showcase images in a slightly messy yet awesome way However, I encounter an issue when some images have ...

Track how far visitors scroll into the inner content area using Google Tag Manager

Our website features a left-side vertical navigation menu. In order to measure scroll depth, we incorporated Tag Manager code. However, the Tag Manager code triggers on every page load due to us fixing the body scroll and implementing a custom scroll for t ...

Modify the attributes of a CSS class according to the chosen theme (selected within the user interface) in Angular 8

I have a custom-built application with Angular 8 where users can switch between two unique themes in the user interface. I have a specific div class that I want to change the background-color for each theme, but unfortunately I am having difficulty achievi ...

Issue with implementing styles on Navbar React component

I'm currently learning Next.js, specifically working with version 10.0.3. In my project, I am using react-bootstrap version 1.4.0 and classnames version 2.2.6. Within my project, I have a component called Navbar that I am trying to style in a certain ...

Attempting to alter the background image through the action of clicking on an image using jQuery, HTML, and CSS

I have created custom weather icons like a sun, cloud, and rainy cloud using Photoshop. My goal is to allow users to click on these icons and change the background image of the website's body. However, despite my efforts, clicking on the images does n ...

Utilizing Bootstrap to allow for seamless text wrapping around a text input field

I am trying to implement a "fill-in-the-blank" feature using Bootstrap, where users need to enter a missing word to complete a sentence. Is there a way to align the text input horizontally and have the rest of the sentence wrap around it? This is my curr ...

Guide to setting up a node.js server that serves HTML files with CSS styling

I am currently working on setting up a simple node.js server for my HTML using http and express. Everything is functioning properly, but the CSS is not displaying as expected. Here is the code snippet for my server setup: const express = require("express ...

Implementing css padding to text preceding images

My content includes text and images in a mix, and I wish to add CSS margin to elements that appear directly before and after the images. Unfortunately, the placement of these elements can vary and is beyond my control. The code snippet below demonstrates ...

Utilize Custom Field to incorporate background videos from websites like Youtube or Vimeo into your content

I've been working on implementing a video background for my website. I came up with a custom code to embed URL links from Youtube and Vimeo using "oEmbed". The process is functioning well, but I'm facing some challenges in setting the background ...

Discovering the proper method to reach the parent element in jQuery while within the click event

How can I use jQuery to access the parent element within a click event? $(document).ready(function () { $(".lv1 li").click(function (event) { this.parentElement.parentElement.textContent = this.textContent; $.ajax({ type: 'post&apo ...

Gathering Servlet details from non-form elements

I am currently in the process of developing an application that is capable of parsing JSON strings. At this stage, I am able to input a JSON string using Java, write it to an HTML document, and then have a JavaScript program read and parse it before ultima ...

Prevent background music from being manipulated

I've implemented an audio HTML element with background music for a game: <audio class="music" src="..." loop></audio> However, I have encountered an issue where upon loading the page, I am able to control the music usi ...

Getting a jquery lightbox up and running

After experimenting with three different jquery plugins in an attempt to create a lightbox that appears when clicking on a link containing an image, I am currently testing out this one: . Despite adding the plugin source in the head and ensuring that the l ...

You cannot embed a YouTube video using its iframe code in an HTML document, according to YouTube's guidelines

I attempted to include a YouTube video in my HTML code, but it kept showing the message "YouTube won't allow connection." Here is the code I used: <center><iframe src="https://www.youtube.com/embed/fcPOsBCwyu8" frameborder="0&q ...

Issue with changing image source on hover using JQuery not functioning as expected

I've been attempting to modify the image src when hovering using JQuery. I'm currently working in Brackets, and when I preview it live in Chrome, everything seems fine. However, when I try to open the file directly in Chrome or IE, it doesn' ...

Is it worth the effort to incorporate HTML5 header, main, section elements, and more into your website?

Do all of these elements simply serve the purpose of making the HTML code easier to read? They don't have any additional functions, right? Unfortunately, we could achieve the same result without them. <Div> <p> Example </p> </ ...

Page not found: unique error on alternate route

My website has different paths and pages in hbs format, such as root, help, and 404. The problem arises when I navigate to localhost:3000/wrong, the site displays correctly, but when I try localhost:3000/help/wrong, the CSS is not applied to the 404 page b ...