简体   繁体   中英

Vertically aligning text in the center of table cell

I know that similar problem have been asked and answered previously on this site, but unfortunately none of the answers have been able to help.

I need my text to vertically align in the center/ bottom of my table row. This i my css text:

h3 {
    vertical-align:bottom;
    font-weight: lighter;
    padding-top: 0px;
    background: url(images/bg3.jpg);
    background-repeat: no-repeat;
    background-position:left bottom;}

If your text is single line, than use line-height = height :

h3 {
   height: 30px;
   line-height: 30px;
   display: inline-block;
}

Use align and valign properties in your table cell:

<table width="100%" border="1">
    <tr>
        <td height="300" align="center" valign="middle">
            <h3>Hello World</h3>
        </td>
    </tr>
</table>

jsFiddle Demo .

From your question it seems you want to vertically align to the bottom and horizontally to the center.. if that is true you should do this:

FIDDLE

td    { text-align:center; vertical-align:bottom;}

*Notice the styles need to be on the table cell and not on the inner element (h3)

good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM