如何使文本和图像在表格单元格中居中?

发布于 2024-08-23 01:23:50 字数 1140 浏览 1 评论 0原文

这是一个简单的网页。我希望文本和图像在单元格中垂直居中。我想要图像左侧的文字,但这应该不是问题......

你能帮忙吗?

<!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>

默认.css。添加您认为合适的内容。

body{

    font-size:12pt;
    }
}

更新:

我收回之前的一些评论,包括说埃文的回答有效。

以下工作有效。注意“*”。埃文的回答不包括。 “”是什么意思?

.style1 * { 垂直对齐:居中; }

Here's a simple web page. I would like the text as well as the image to be vertically centered in the cell. I would 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> </td>
    </tr>
    <tr>
        <td></td>
        <td> </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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枯寂 2024-08-30 01:23:50

星号表示“该类别的任何后代”;但要小心使用它,因为这意味着所有后代元素都将接收特定的样式。

注意 1:请注意 CSS 中的右大括号过多。

注意2:此外,如果文本比图像大,您收到的其他答案将不起作用。您没有给出图像的尺寸。

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.

深海不蓝 2024-08-30 01:23:50

因为您正在使用表格进行格式化。只需添加 .style1 { Vertical-align: middle } 即可。文本应保留在图像的左侧。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文