How can I position 7 images absolutely within a specific div?

I've been working on a website where users can have their avatars displayed using a JS function that loads 7 different images onto the page. These images correspond to different elements such as skin base, hair, eyes, mouth, shirt, shoes, and pants, all of the same size but stacked on top of each other.

Here's a snippet of the HTML code:

<body onload="LoadCharDiv('codas', 'AvatarImgFrame');">
<div id="MainBody">
    <div id="DataFrame">        
        <div class="DataObjects"><div class="InfoLabels">Account Level:&nbsp;</div><div class="InfoData" id="LevelData"><?php echo($row['level']); ?></div></div>
        <div class="DataObjects"><div class="InfoLabels">Profile Views:&nbsp;</div><div class="InfoData" id="ProfileData"><?php echo(mysqli_num_rows($views)); ?></div></div>
        <div class="DataObjects"><div class="InfoLabels">Messages:&nbsp;</div><div class="InfoData" id="MessageData">0</div></div>
    </div>


    <div id="AccountFrame">
        <div id="AccountAvatar">
            <div id="AvatarImgFrame"><img src="http://upload.wikimedia.org/wikipedia/commons/c/cd/Placeholder_male_superhero_c.png" id="Acc_img"/></div>
            <input type="button" id="sendPm" value="Send Message" name="sendPm"/>
        </div>
        <div id="AccountInfo">
            <div id="NameObject" class="DetailObjects"><div class="DetailLabel"><?php echo($row['first_name'] ."&nbsp". $row['last_name'] ."&nbsp;". "(".$row['username'].")");?></div></div>
            <div class="DetailObjects"><div class="DetailLabel">Age: </div><div class="DetailInput" id="DetailAge"><?php echo($age); ?></div></div>
            <div class="DetailObjects"><div class="DetailLabel">Country: </div><div class="DetailInput" id="DetailCountry"><?php echo($row['country']); ?></div></div>
            <div class="DetailObjects"><div class="DetailLabel">Registered: </div><div class="DetailInput" id="DetailReg"><?php echo($timeon." Days Ago"); ?></div></div>
            <div class="DetailObjects"><div class="DetailLabel">About Me: </div><div class="DetailInput" id="DetailAbout"><?php echo($row['about']);?></div></div>
        </div>


    </div>
</div>
</body>

The "LoadCharDiv()" function in JavaScript places the images into a div based on the character code provided. Here's how it works:

function LoadCharDiv(codas, div){
var code = "1c0c1c0c1c2c1";
var data = code.split("c");
var skins2 = [skins[data[0]], eyes[data[1]], hair[data[2]], mouth[data[3]], pants[data[4]], shoes[data[5]], torso[data[6]]];
var inhtml = "";
for(var d = 0; d < skins2.length; d++){
inhtml = inhtml + "<img src='"+skins2[d]+"'/>";
}
document.getElementById(div).innerHTML = inhtml;
}

Also, here's the CSS included in the page:

*{
    margin: 0px;
    padding: 0px;
    font-family: 'Ubuntu', sans-serif;  
    }
body{
    background-color: #111111;
    margin: 1%;
}
#MainBody{
    width: 60%;
    margin-left: auto;
    margin-right: auto;
    height: 800px;
}
...

If you take a look at the current positioning of the character image with CSS, it seems like it's placed to the side of the page. I'm looking for a way to adjust its position to be right above the "Send Message" button and remain fixed there without floating around if the page is resized.

Your suggestions and advice are greatly appreciated!

Answer №1

Your positioning is correct, however, absolute elements do not affect the normal content flow so it is important to assign a height to the container of these elements.

Here is the link for reference: http://jsfiddle.net/rwh3emp2/1/

#AvatarImgFrame serves as the container for the image

#AvatarImgFrame {
    height: 230px;
}

You can eliminate the height from #AccountAvatar

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

What is the best way to extract the HTML input id using observeEvent in shiny?

How can I capture the HTML input id using observeEvent in shiny? shinyApp( ui = basicPage( HTML('<input type="button" name = "b1" value="Travel time"/>')), server = function(input, output, session) { o ...

A guide on how to efficiently retrieve all images stored in a specific directory

I attempted to showcase all the images from a single directory using jQuery, but unfortunately it is not functioning as expected. My folder setup includes an 'images' folder and a 'js' folder. I followed this question on Stack Overflow ...

Performing addition operations on numbers entered through an HTML input field using PHP

I am looking to create a feature where the numbers entered in an input form are added together. I need to store these numbers in an array and have them display in a new line when a button is clicked. Here is the HTML code for the input field and button: ...

Angular error message: Trying to access the property 'name' of an undefined object leads to a TypeError

I'm having trouble phrasing this question differently, but I am seeking assistance in comprehending how to address this issue. The error message I am encountering is as follows: TypeError: _co.create is not a function TypeError: Cannot read property ...

What are some strategies for preventing a child component from triggering a re-render of its parent component in React Native?

My child component is causing the parent component to re-render when it's clicked, which is not the desired behavior. I initially thought that removing all the setState() functions in the child component would prevent this, but then I realized that As ...

What could be causing the context of 'this' in Javascript to remain unchanged in this particular scenario?

Currently, I am exploring the concept of 'this' in Javascript and have encountered a perplexing situation. After delving into how JavaScript functions operate as outlined here, I grasped that when a function is invoked on an object, the object i ...

Achieving Top Alignment of Items in CSS/HTML with the Help of React.js

I recently created a navbar in react and I'm struggling to align my list of menu options to the top. I was trying to follow a tutorial on YouTube but I can't seem to locate the step where this alignment was done. (YouTube Tutorial Link). Despite ...

Steps to customize the appearance of a button within a file input field

When implementing the file input in my code on a Mac, I noticed that the alignment appears off. On all other devices, it looks just fine. However, when I try to apply a style specifically to the 'Choose file' button, the style also gets applied t ...

What is the best way to use JavaScript to conceal a section of a form div?

After receiving some code from a certain platform and implementing it to hide part of my form div element, I noticed that the element hides and unhides quickly when running in a browser. This rapid hiding and showing behavior occurs when clicking on the bu ...

Text fields do not show a cursor icon

On the website http://www.legrandclub.net, there are two text fields. Everything works fine in all web browsers except for Internet Explorer. When I click on one of the text fields, the cursor is not displayed, although it is possible to write text. What c ...

Preserve the existing value and then check it against the updated value of a variable within JavaScript

I utilized an API that supplies me with information in JSON format, retrieved the price of a specific currency, and presented it on a screen using JavaScript. I encapsulated this process within a function that dynamically updates the information at set int ...

Displaying all items in a collection as HTML using Node.js

I am looking to showcase all the items in my mongodb collection as HTML. In the past, I have accomplished this with simpler tasks, such as... router.get('/', function (req, res) { res.render('home', { title: 'Express', u ...

Refresh the CSS without having to reload the entire page

I am working on a web page that operates on a 60-second timer. The code snippet below is responsible for updating the content: protected void RefreshButton_Click(object sender, EventArgs e) { ReportRepeater.DataBind(); ReportUpdatePane ...

Problem encountered in Vue.js web application when running NPM, resulting in Error 126

When attempting to compile my Vue.js application using the command npm run prod, I encountered the following error: sh: /Users/antoinevandenheste/Downloads/magicfactory-1/node_modules/.bin/webpack: Permission denied npm ERR! code ELIFECYCLE npm ERR! errno ...

Using Angular to bind the ngModel to a variable's object property

In my application, I am working with a user object that looks like this: let user = {name: "John", dob:"1995-10-15", metadata: {}} The metadata property of the user object is initially empty. I want to add a new property to the metadata object based on u ...

Converting HTML and CSS into a PDF using JavaScript

I am on the lookout for libraries that can cater to my specific needs, as I haven't found one that fits perfectly yet. My setup involves Node.js on Express.js for the backend, and html/css/js for the front-end. Browser support includes IE8 and up, chr ...

The duration for which an API Access Token remains valid is extremely brief

I recently started working with APIs and my current project involves using the Petfinder API v2 to develop a website that allows users to search for adoptable animals. The API utilizes OAuth, requiring a key and secret to obtain a token via CURL. However, ...

I have found that I can load a CSS file using Node Express, however, it seems to be malfunctioning. On the other hand, some

I have added app.use(express.static(path.join(__dirname, 'public'))); to my app.js file. Now I am using bootstrap.css along with my custom CSS file main.css. index.html: ┊ <meta http-equiv="Content-Type" content="text/html; charset=UTF- ...

Tips for integrating DataTables selection filtering functionality

Here's a snapshot of my screen I'm attempting to utilize data tables This is what I have on the main page $('#student-listing-table').dataTable(); $('#student-listing-table').find('label').html('Search By Nam ...

Where is the session management functionality situated within an OAuth-enabled web application?

When creating an oauth service (such as for Facebook or Gmail) enabled web application using Angular or React, where should session management be located? Should user sessions be maintained on the hosted server or within the oauth service itself? This is ...