Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Centering Javascript Images HELP! :)

I have this code, and just want to center the image objects being displayed from my arrays.

PHP Code

<?php 
    
function redeal(){

        var 
centered = document.createElement('div');
        
centered.className = 'centered';

            for(
x=0;x<playerarray.length;x++){
                
document.body.appendChild(playerarray[x].image);
            }

            
document.body.appendChild(layer); //this just adds a 'br', declared globally

            
for (x=0;x<opponentarray.length;x++) {
                
document.body.appendChild(opponentarray[x].image);
            }    
    } 

And in the CSS I have:

PHP Code

<?php 
.centered {display: block; margin-left: auto; width: 500px; margin-right: auto } 

Just not sure how it works...or what it should look like..

Thanks Guys!
I'm not sure if I'm right here, as I hardly ever do webpage stuff, but couldn't you use HTML to center your image when you call the function? Sorry if I'm wrong, not my cup of tea.
You want to center the images in the <body> or in the specific <div>?

If inside the div, ignore all the other CSS you have for class ".centered. Just set "text-align: center; width: 500px" for the class .centered and that should do it. A block by default has display: block.

If inside the body, you have to set "text-align: center" to the body, then "display: inline-block" for the div.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Help] by ExodianJul 30, 2015 07:20 PM 5 98 Jul 30, 2015 07:20 PM
Last Post: Exodian
by AvocadoJan 22, 2015 08:35 PM 2 103 Jan 22, 2015 08:35 PM
Last Post: AdGateDan
[Help] by RarinatorAug 23, 2014 07:36 PM 3 97 Aug 23, 2014 07:36 PM
Last Post: Knar.