Ways to maintain image alignment regardless of the size of the window or device?

Let's set the scene.


I'm working with 2 images, a background image for a div and another regular image inside that same div. My question is, how can I ensure that both images are always in the exact position of each other, even when viewed on different window sizes or devices? Check out this illustration to see what I mean.

https://i.sstatic.net/AOFBT.png

Any assistance would be greatly appreciated. I must admit, my HTML and CSS skills aren't top-notch. Here's the code snippet:

.located {
  background: url(images/located.jpg);
  background-repeat: no-repeat;
  background-position: 50% 25%;
  width: 100%;
  height: 80%;
  z-index: -1;
  position: fixed;
}
.userimage {
  margin-left: 46%;
  top: 20%;
  position: absolute;
}

html

<div class="located"></div>

<div class="userimage">
    <?php echo $userSkin3D;?>
</div>

Answer №1

Website Design Elements:

<div class="profile-card">
  <div class="avatar-image">
      <?php echo $userAvatar;?>
  </div>
</div>

CSS Styling:

.profile-card {
  background: url(images/profile-background.jpg);
  background-repeat: no-repeat;
  background-position: center top;
  width: 100%;
  height: 80vh;
  z-index: -1;
  position: fixed;
}

.avatar-image {
    top: 20%;
    left: 50%;
    position: inherit;
}

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

A more efficient method for adding HTML content to an element

I have been working on implementing an infinite scroll feature like this: <script type="text/javascript"> $(function () { var page = 1; var $ol = $('#namesList'); var $waypoint = $('#namesWaypoint'); ...

Dealing with errors in AJAX divs

Utilizing an AJAX-based script known as AJAXTwits, I've been able to seamlessly load multiple Twitter timelines for a sports team into a designated div. The standout features of this script include its ability to combine various timelines into a singl ...

Enter the spotlight with all the information you need about AngularJS

Can someone please help me figure out how to display the post->id with a fade in effect? I've tried searching for a solution but haven't had any luck. Your assistance would be greatly appreciated!!! *I apologize in advance if my language is n ...

Display upon hovering, conceal with a button located within a popup container

There seems to be an issue with the code below. Even though it works perfectly in jsfiddle, it breaks in my Chrome and other browsers right after displaying the ".popup" div. Can anyone point out what I might be doing wrong? I found similar code on this si ...

The usage of an import statement is not permissible outside of a module

Having some trouble using the mathjs library to calculate complex solutions for the quadratic equation. No matter how I try to import the library into my code, I keep encountering errors. Initially, I attempted this method: At the top of my root.js file, ...

Newbies struggle with styling HTML elements within nested IDs

I am new to learning HTML and struggling with working with IDs and classes within IDs and classes. Based on my understanding, an ID is denoted by a # symbol. So if I wanted to style an ID within another ID, would it be written like: #ID1 #ID2 { ... ...

What is the best way to create pages that showcase 10 posts each?

Currently, I am facing a challenge with displaying 100 posts using the Fetch API on one single page. I am looking for a way to create separate pages where each page would showcase only 10 posts. Below is my existing JavaScript code: fetch('htt ...

Creating an HTML file with a Windows-inspired icon and file name design using CSS

I searched everywhere on the internet but couldn't find a solution. If anyone knows of a similar link to my question, please share it with me. I am trying to achieve a design similar to Windows icons and file names in HTML using CSS. Please refer to ...

Tips for utilizing the "rel" attribute in conjunction with an image map

I have been successfully using a jQuery popup to display different DIVs when clicking on different links. However, I now need it to work with an image map. It appears that the "rel" attribute is not functioning properly with the image map. Check out the ex ...

Show either the abbreviated or complete form of the text

Initially, the default display should show the shortened version of each element (one line with "..." included). All items must consistently be shown in either the shortened or full-length version. If all items are in shortened mode - clicking on one item ...

Flexbox does not support sub-columns

I'm having trouble integrating these two columns along with their sub-columns. I have to resort to using this structure instead: <div class="custom_classes"> <div class="custom_classes">col1</div> <div class=&q ...

Updating the UI in Angular for keyboard events is not working as expected

Looking to update the page based on keyboard events. I've connected the keyboard event using $window.document.onkeydown. (I understand it's not ideal, but it should still work) However, despite changing the model, I'm not seeing any updates ...

Images in jQuery rotate depending on the movement of the cursor

My oven has knobs that rotate when you hover over them, but they only turn clockwise. Is there a way to track which direction the cursor enters the image from - left or right - and rotate it accordingly? For example, clockwise if from the left, countercl ...

Steps to center the background color and text on screen:1. Determine the dimensions of

I've tried many different approaches, but I'm struggling to figure it out. In my code below, the h1 and h2 elements have a gold and black background respectively. Although I've set their width to 500px, they are stuck at the top left corner ...

Mastering the art of obtaining XPaths through Selenium WebDriver

While working on test automation for a section of Outlook Web App, I focused on checking a designated test mailbox that receives emails from our company. I needed to verify specific texts within an email using Assert, but encountered difficulty in identify ...

Full-Width Bootstrap Element

I am looking to design a pattern of alternating colored blocks that span 100% of the screen. An example of the "ideal" layout can be seen in the attached illustration, along with the current layout. Preferred design: Current layout: My initial approach ...

Looking to convert a JSON file to an Excel file using JavaScript and HTML? Learn how to upload and transform your data with ease!

I am looking for a way to upload and convert JSON files containing information such as: [ { "First Name": "Paul", "Last Name": "Craig", "Gender": "Male", " ...

Expandable Menu that slides up and down

Here is a link to an Accordion Menu I have created: https://jsfiddle.net/wfr57s57/ This piece of JQuery Code controls the functionality: $(".menu-item").click(function(e) { var allContents = $(".menu-content"); e.preventDefault(); if(allC ...

Trouble Aligning Bootstrap Dropdown Menu Link with Other Navbar Links

Issue with dropdown links not aligning properly in the Bootstrap navbar. The positioning seems off and can be seen in the screenshot provided where the blue outline represents the ".dropdown" https://i.stack.imgur.com/QmG7v.png Facing a similar problem a ...

Delete the "img" and "a" elements from the content within the specified node

Is it possible to only extract text from my HTML content? var sb = new StringBuilder(); doc.LoadHtml(inputHTml); foreach (var node in Doc.DocumentNode.ChildNodes) { if (node.Name == "strong" || node.Name == "#text" || node.Name == "br" || no ...