Unable to align two overlapping images centrally

https://i.sstatic.net/5Szut.jpg

Two identical images are displayed correctly with a semi-transparent 'logo' on top of a base green image. However, they are positioned on the left and I need them both to be centered on the screen. I can't seem to figure out what I'm missing here?

<div class="portrait-image-wrapper">
    <img src="../image.jpg" class="base-photo"/>
    <img src="../logo.png" class="logo"/>
</div>

Here is the CSS code:

html,body {
  width: 100%;
  height: 100%;}

.portrait-image-wrapper {
position: relative;
background-size: contain; 
background-repeat: no-repeat;
background-position: center center; 
width: 467px; 
height: 700px;}

.base-photo {
background-repeat: no-repeat;
position: absolute; 
z-index: 1;}

.logo {
position: absolute; 
top: 0px; 
left: 0px;
z-index: 2;}

I attempted to add these properties to the portrait-image-wrapper class without success...

display: flex; 
align-items: center;

Answer №1

In order to properly position the .portrait-image-wrapper in the center of the screen, you should include the following CSS code:

html,body {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

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

When it comes to HTML and Javascript, there is a distinct contrast between an ajax call and altering the content of an

I am currently working on coding a JavaScript function to allow liking a specific post on Tumblr. I came across this helpful resource for reference. Initially, I attempted using an ajax call instead of modifying the source of an iframe, but unfortunately, ...

Tips for creating distinct hover descriptions for each element in an array

My dilemma may not be fully captured by the title I've chosen, but essentially, I am working with a list of names and I want each one to display a unique description when hovered over with a mouse. On the surface, this seems like a simple task, right ...

Merge the values of two select tags into a single textbox

There are two select Tags along with a text box included. <select name="select1"> <option>1</option> <option>2</option> </select> <select name="select2"> <option>1</option> <option>2 ...

What steps can I take to ensure that both of my codes are functioning properly in order to consistently operate the D3?

In my index.php file, I have HTML code that loads a d3 liquid gauge. When I open this in a browser with a static integer inserted into the code, it works perfectly. Then, I have another file called Tdata.php which queries MySQL and returns a table in JSON ...

What is the best way to vertically align a Material UI component to occupy the remaining space within a container

Issue with Material UI/Grids for Login Page As a newcomer to Material UI/Grids, I am currently working on creating a login page where the layout is split into two parts. The left side occupies 5 column spaces while the right side takes up 7 column spaces. ...

What is the best way to add padding between form elements in Bootstrap 4?

Is there a way to add space between form elements in Bootstrap 4? The code snippet below shows an example where the full name has spacing from '@' but the username does not have any. Any suggestions on how to fix this? <form class="form-inlin ...

Create dynamic animations for HTML lists with seamless transitions

I am looking to create a smooth animation effect for an HTML list that moves from left to right and vice versa with a fixed length. The issue I am encountering is that when I click on the right button, it is replacing the list elements instead of animating ...

Utilize XML and Javascript to create a captivating donut chart

I am currently experimenting with XML and JavaScript to generate a donut chart. I attempted to implement this JS code. However, I am struggling to create XML that is compatible with the JS. var SCIENCE = 0; var ART = 0; var MATH = 0; $(document).ready ...

The HTML table seems to be inexplicably replicating defaultValue values

I'm encountering an issue where, when I use JavaScript to add a new table data cell (td), it ends up copying the defaultValue and innerText of the previous td in the new cell. This is confusing to me because I am simply adding a new HTML element that ...

Using Bootstrap4 to merge rows into a single column or apply rowspan in Bootstrap

Hey there, I have a specific requirement that I need help with. Check out the image here. I want to enable the LCM information box when the LCM checkbox is checked. Below is my code: <div class="panel-body "> <div class="c ...

To activate an underline on text, simply right-click and select "text

All the anchor tags on my website have been styled with text-decoration: none. Additionally, I have added a CSS rule based on a helpful answer: a, a:hover, a:active, a:visited { text-decoration:none; } However, whenever I right-click on a link on my ...

Guide to adding a Font to a server

Recently, I downloaded and installed a font on my computer and incorporated it into my project. While it appeared to work perfectly on my local system, I encountered issues when I uploaded the page to the server. How can I ensure that the font is properly ...

Outline along a single edge

Is there a way to add an inset border to an HTML element on just one side, without using an image as a background? I've been stretching and positioning images for this purpose in the past, but I recently discovered the outline CSS property. However, i ...

What is the best way to test out CSS effects before they go live

I enjoy customizing the CSS, like the posted dates on my portfolio How can I make these changes without affecting the public view of the website? One suggestion from a forum was to use .date {visibility:hidden;} ...

Tips for Making JQuery UI Droppable Work with Multiple Elements

I've been tasked with modifying a piece of code that currently allows users to drag one row from a table to a div. The new requirement is to enable users to select multiple rows and drag them all to the div. I'm struggling to tweak the existing c ...

Align the middle element in a dynamic row

There is a row consisting of three elements: left, center, and right. However, the problem lies in the fact that the center element is not aligned at the screen level, but rather at the row level. Is there a solution to align this element at the screen l ...

During the process of converting documents to HTML, any graphics or shapes may not be accurately translated into HTML format

I am looking for a way to display a doc file in a dialog box on a browser. To achieve this, I converted the doc file into an html file successfully. However, I encountered an issue when the doc file contained graphics or shapes - these elements were not co ...

Stack three DIVs vertically on the entire screen with a fixed page margin, ensuring no need for a scroll bar

I need help creating a layout with 3 DIVs stacked vertically, each taking up one third of the screen without causing a scroll-bar to appear. I also want an 8px margin around all three of them. Here's an image for reference... example image Ultimatel ...

What is the best way to manage photos from your phone without having to upload them online?

I'm currently developing an application using AngularJS/Javascript, HTML, and CSS within a cloud-based environment on c9.io. My next task is to create and test an app that can access the phone's photo album, apply filters to images, and I'm ...

Photos inside a flexbox do not resize correctly

When placing 2 images inside a flexbox with the column direction, I anticipated that the images would resize accordingly when adjusting browser window size. However, this is not the case. Regardless of the CSS styles applied, I am unable to maintain the o ...