Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

middle aligning something not in a table, XHTML trans

Status
Not open for further replies.

phrozt

IS-IT--Management
Jul 8, 2004
78
US
I'm trying to align an image in the middle of an element (div), and I can't figure out how to do it.

margin: auto; does't take care of it, and vertical-align: middle only works for table cells.

Can anyone help me w/this?
 
Hmm.. let me clarify a few things after my first post.

I'm trying to VERTICALLY align something in the middle. Centering it horizontally is no problem

I'm making a multitude of these pages, and the images on each are different heights and widths. I'll also post the code I have so far, so that you may refer to it.

<div id="workRight">
<img class="feature" src="images/id_carbonic.gif" width="174" height="24" alt="carbonic" />
</div>

#workRight {
width: 200px;
height: 240px;
float: left;
text-align: center;
}

.feature {
margin: auto;
margin-top: 20px;
}
 
anyone figure anything out for this?
 
I cannot test this in other browsers right now and I fear that it might not work, but this works with a doctype in IE6:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

<style type="text/css">
#workRight {
    width: 200px;
    height: 240px;
    float: left;
    text-align: center;
    background: red;
    font-size: 215px;
    overflow: hidden;
    line-height: 1em;
}

.feature {
    vertical-align: middle;
}
</style>

<div id="workRight"><img class="feature" src="images/id_carbonic.gif" width="174" height="24" alt="carbonic" /></div>
Red background is there to help see the centering.
 
well, that makes a little bit of difference on IE - it actually puts stuff low, but close to the middle, but it does nothing to mozilla at all :/

Thanks though!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top