Placing an image on top of a background image in CSS while maintaining a fixed aspect ratio

My CSS code is currently resizing the background image to fit the browser size while keeping the center of the image in the center of the window. Now, I need to add another image, like an icon in a circle, at the center following the same aspect ratio rule. How can I apply the same code to maintain the aspect ratio of my second image? And more importantly, how can I overlay another image onto the background at the center? I have even included an image of the background created using Photoshop!

CSS

    #stage {
      position:fixed;
      top:-50%;
      left:-50%;
      width:200%;
      height:200%;
    }

    #stage img {
      position:absolute;
      margin:auto;
      min-width:50%;
      min-height:50%;
      top:0;
      left:0;
      right:0;
      bottom:0;
    }

    @media screen and (max-width: 512px) {
      #stage img {
      width:100%;
      height:auto;
    }

HTML

    <div id=stage>
    <img src="cutest_child_in_the_world-wallpaper-5120x3200.jpg" />
    </div>

Answer №1

If your goal is to superimpose another image in the same position as the first one, you can simply reuse your current code. Add another div with a different image and update the ID #stage to a class.

The second image will need some level of transparency to allow visibility of the first image... and it should ideally be the same size to achieve the desired visual effect.

Check out this jsfiddle for reference.

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

Troubleshooting: Why isn't my jQuery Click Event functioning in Mozilla but working perfectly fine in

While I know this question has been asked before, I can't seem to locate the posts I remember reading about it. I apologize for any duplication, but I am trying to implement a "click anywhere BUT here to close element overlay" effect on my personal we ...

issue with manipulating URLs in Express routing

Looking for assistance with Express routing. I want users to only see localhost:3000/page2 when they go to /page2, instead of localhost:3000/page2.html I have three HTML pages - page1.html, page2.html, and page3.html. I've created a server using Expr ...

Tips for retrieving a selected date from an HTML textbox labeled as "Date"

My goal was to find the differences between two dates by utilizing an HTML Date textbox. <input type="text" name="datein" id="datein" value="" class="inputtexbox datepicker" style="display: none" is-Date/> <input type="text" name="dateto" id=" ...

Designing a Scrollable tbody Element while Preserving the Integrity of the tbody Columns

Currently, I am attempting to implement a scrollable tbody in order to run a React package smoothly. The challenge lies in achieving a scrollable tbody without having to resort to using display: block on the tbody element. Unfortunately, this solution dis ...

Issue with responsive design: Media queries not applying max-width

GOAL I want the content of my page to adjust to screen sizes that are smaller than 600px wide. ISSUE When using the responsive tool in Chrome, preset screen sizes like iPhone X do not apply media queries properly. Even manually adjusting the screen size ...

Editable dropdown in Angular - customize editability according to selected option

UPDATE 1: I have created the initial sample code as a foundation for proper implementation. UPDATE 2: Successfully developed a functional model. Please refer to the answers. During my research, I came across this library: This library enables the addit ...

Creating a unique paragraph style for my blog in SharePoint 2013 - step by step guide!

Managing a Share Point 2013 web site with a blog presents the challenge of incorporating special text content in posts. To ensure consistency, it's essential to add additional styles that can be applied to all posts. Normally, these styles are accesse ...

What is the best way to effectively incorporate Bootstrap into an HTML project?

Here is the code snippet I am working with: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name ...

Greetings, username, following successful login

Upon first accessing the system, the user will be prompted to log in. If the login is successful, the user will be redirected to the index.php page; if not, they will be asked to re-enter their credentials. My goal is to have the username displayed on the ...

Checking for the existence of a CSS selector in Jasmine test suite

Testing out the latest version of Jasmine and Karma with an AngularJS instance. I attempted: expect(element('a.topic-heading-link-10')).toBeDefined(); However, I received this response: expect undefined toBeDefined undefined http://example.co ...

Displaying live data from a spreadsheet directly on a sidebar

My goal is to extract data from another sheet in the same spreadsheet and present it as a dropdown selection in the sidebar. The code.gs file contains a function called getVisualData() that successfully retrieves the desired list: function getVisualData() ...

Enhance Your Page with a Widget Using Bootstrap

I am looking to incorporate a basic text box on the side of my webpage. https://i.sstatic.net/qzwIh.png Currently, I have a table on the page. Upon adding the widget, I need the table to reduce its width. ...

css: positioning images with overlap in a responsive layout

Two divs have been created with background images, both displaying the same image but in different colors - one grey and the other green. These images are waveforms. Initially, only the grey image (div1) is visible while the green image (div2) remains hid ...

The functionality of the disabled and checked options on the radio button seems to be malfunction

Within an Angular HTML document, I have a set of radio buttons that share common names. I am attempting to update their disabled and checked properties from a .ts file, but the changes are not taking effect. Here is the code snippet: let elements = docume ...

Prevent users from accessing the refresh and back/forward functions in all browsers

I'm currently developing an evaluation system where candidates take exams. The page displaying questions and choices is rendered within an iframe. This iframe page also includes a JavaScript timer. To prevent candidates from refreshing the page using ...

What could be preventing this code from automatically scrolling to the designated class when a key is pressed?

When a key is pressed on the document, the default action is prevented and the element with the ID "show-all-win" is animated to scroll to the position of the element with the class "key_" plus the key code of the pressed key. This animat ...

Having trouble getting Owl Carousel to function properly within an AngularJS partial view?

I just started working on a single page application using AngularJs. Here is a snippet from my Index.html: <!DOCTYPE html> <html data-ng-app="myApp"> <head> <meta charset="utf-8> <meta name="viewport" content="width=devi ...

Python script that utilizes BeautifulSoup to parse and select HTML code

@bot.event async def on_message(message): response = requests.get(f"https://steamid.io/lookup/" f"{on_message}") steamid = BeautifulSoup(response.text, "html.parser") print(steamid.prettify()) Upon ...

Concealing HTML pages in Node.js: A step-by-step guide

I have a specific requirement where my website's html pages should only be accessible to users who are logged in. However, when I used the command below, my html pages became public: app.use(express.static('public')); For instance, I do no ...

Unusual alterations to HTML and CSS to meet specific needs

Struggling with bringing my website ideas to life! My header contains a navigation bar, followed by a centered chat box within a fixed <section>. Want the left and right side of the chat box to be content areas that scroll in sync while the chat box ...