gpt4 book ai didi

表格 Rowspan 与 Fluid Height 的 CSS 等价物

转载 作者:技术小花猫 更新时间:2023-10-29 10:26:09 28 4
gpt4 key购买 nike

我正在尝试使用 CSS 完成以下任务:

<table border="1" width="300px">
<tr>
<td rowspan="2">This row should equal the height (no fixed-height allowed) of the 2 rows sitting to the right.</td>
<td>Here is some sample text. And some additional sample text.</td>
</tr>
<tr>
<td>Here is some sample text. And some additional sample text.</td>
</tr>
</table>

alt text

我看到的实现此目的的示例使用固定高度或允许内容环绕左栏。有没有一种使用 CSS 来实现此目的的优雅方法?

最佳答案

首先,你所做的对我来说看起来像一张 table ,所以你可能需要考虑一下。然而,用 CSS 来做它有点棘手(除非你用 CSS 做表格样式)。以下代码有效,但不会使框中的文本垂直居中:

<html><head><title>Test2</title></head><body>
<div style="width:300px; padding: 2px; border: 1px solid black;">
<div style="float:right; width: 100px;">
<div style="border: 1px solid black; margin-bottom: 2px;">
Here is some sample text. And some additional sample text.
</div>
<div style="border: 1px solid black;">
Here is some sample text. And some additional sample text.
</div>
</div>
<div style="border: 1px solid black; margin-right: 102px;">
<div>
This column should equal the height (no fixed-height allowed) of the 2 rows sitting to the right.
</div>
<div style="clear: right; margin-bottom: -1px;"></div>
</div>
</div></body></html>

CSS 中的表格单元格更简单:

<!DOCTYPE html>
<html><head><title>Test2</title></head><body>
<div style="display: table; width:300px; border: 1px solid black; border-spacing: 2px;">
<div style="display: table-cell; border: 1px solid black; vertical-align: middle;">
This column should equal the height (no fixed-height allowed) of the 2 rows sitting to the right.
</div>
<div style="display: table-cell; width: 100px;">
<div style="border: 1px solid black; margin-bottom: 2px;">
Here is some sample text. And some additional sample text.
</div>
<div style="border: 1px solid black;">
Here is some sample text. And some additional sample text.
</div>
</div>
</div>
</body>
</html>

关于表格 Rowspan 与 Fluid Height 的 CSS 等价物,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2611083/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com