How to center my div in a table using CSS?

I am trying to add a slide show to one of my sites. The whole page is laid out in an HTML table (which I hate with passion and do not choose). I want to focus my slideshow inside this footer. This is what my CSS looks like:

#slideshow {
position:relative;
}

#slideshow IMG {
position:absolute;
z-index:8;
opacity:0.0;
}

#slideshow IMG.active {
z-index:10;
opacity:1.0;
}

#slideshow IMG.last-active {
z-index:9;
}

Here is my jQuery function for changing images:

function slideSwitch() {
var $active = $('#slideshow IMG.active');

if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

// use this to pull the images in the order they appear in the markup
var $next =  $active.next().length ? $active.next()
    : $('#slideshow IMG:first');

$active.addClass('last-active');

$next.css({opacity: 0.0})
    .addClass('active')
    .animate({opacity: 1.0}, 1000, function() {
        $active.removeClass('active last-active');
    });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});

And finally, here is the slide show div inside the table:

<td bgcolor="red" align="center" valign="top"> 
<div id="slideshow">
    <img src="2009Slideshow\1.jpg" alt="Slideshow Image 1" class="active" />
    <img src="2009Slideshow\2.jpg" alt="Slideshow Image 2" />
    <img src="2009Slideshow\3.jpg" alt="Slideshow Image 3" />
    etc...
    etc...
</div>                    
</td> 

So why can't I get my slideshow to focus inside this column?

+5
source share
6 answers

, css "text-align: center;". , "margin-left: auto; margin-right: auto;" . "div" div .

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">   
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">     
    <head>      
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />   
        <title>Centering</title>
    <style type="text/css">
      table{
       border:1px solid black; 
      }
      span{
        background-color:red; 
        color:white;       
      } 
      td{
        text-align:center;
        width:200px; 
      }
    </style>
  </head>
  <body>
    <div class="item" id="item1">
      <table>
        <tr>
          <td>
            <span>Hi there!</span>  
          </td>
        </tr>        
      </table>
    </div>    
    </body>
</html> 
+15
#slideshow {
margin: 0 auto;
}

and also text-align: center

+5

, :

< div style = " height: 100px; width: 100px; display: table-cell; text-align: center; vertical-align: middle;" >
     < img src=" images/myPicture.png " >
 </ >

+1

, 50 rep.. doh. , , , - doctype IE6, quirks. .

<?xml version='1.0' encoding='UTF-8'?>

, .

0

, text-align: center td.

, , left to td/2 - img_width/2. , 80 200px wide td,

#slideshow img {position:absolute; left:60px; opacity:0; z-index:8;}

, javascript.

IE . filter: alpha(opacity = 50);.

0

 div#slideshow {
    margin : 0 auto;
    width : 200px;
}

(old?),

td {
    text-align : center;
}

.. "" , (divs)

also does not display the standard display property value for td, i.e. because it does not use table-cell, and text-align will not work inside inline elements, so another possible aproach would have to wrap it around another div:

<td>
<div id="slideshow_container">
<div id="slideshow">
...
</div>
</div>
</td>

and css

div#slideshow {
    margin : 0 auto;
    width : 200px;
}
div#slideshow_container {
    text-align : center;
    width : 100%;
    height : 100%;
}
0
source

All Articles