开发者

How do you center text and image in a table cell?

开发者 https://www.devze.com 2022-12-21 20:07 出处:网络
Here\'s a simple web page. I would like the text as well as the image to be vertically centered in the cell. I w开发者_JS百科ould like the text to the left of the image, but that shouldn\'t be a probl

Here's a simple web page. I would like the text as well as the image to be vertically centered in the cell. I w开发者_JS百科ould like the text to the left of the image, but that shouldn't be a problem...

Could you help?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
    <link href="default.css" rel="stylesheet" type="text/css" />

</head>

<body>

<table border="1" style="width: 100%">
    <tr>
        <td class="style1">Text<img src="PdfLink.jpg" alt="Whatever"/></td>
        <td>&nbsp;</td>
    </tr>
    <tr>
        <td></td>
        <td>&nbsp;</td>
    </tr>
</table>

</body>

</html>

default.css. Add to it as you see fit.

body{

    font-size:12pt;
    }
}

Update:

I take back some previous comments, including saying that Evan's answer worked.

The following worked. Note the "*". Evan's answer didn't include the . What does the "" mean?

.style1 * { vertical-align: middle; }


The asterisk means "any descendent of this class"; be careful using it, though, because it means ALL descendant elements will receive a particular style.

Note 1: Be aware that you have too many right braces in your CSS.

Note 2: Also, the other answer you received won't work if the text is bigger than the image. You didn't give a size for the image.


Because you're using a table for formatting. Simply add .style1 { vertical-align: middle }. The text should remain to the left of the image.

0

精彩评论

暂无评论...
验证码 换一张
取 消