gpt4 book ai didi

html - 在 HTML/CSS 中垂直显示表格

转载 作者:行者123 更新时间:2023-12-05 08:18:06 25 4
gpt4 key购买 nike

我正在执行从 htlm 生成 PDF 文件的任务,我有一个超过页面宽度的表格,所以我正在寻找一种垂直显示该表格的方法。

如何在html/css中做到这一点(我使用的是Bootstrap 4),请看下面的源码和图片:

源代码:

<!DOCTYPE html>
<html>
<head>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Larry</td>
<td>the Bird</td>
<td>@twitter</td>
</tr>
</tbody>
</table>
</body>
</html>

当前结果:

enter image description here

预期结果:

enter image description here

提前致谢

最佳答案

您可以使用 transform CSS property 实现相同的效果。您可以使用 position: absolute 或通过准确设置 margins 或以正确的方式使用 transform-origin 来调整表格的放置适合你的需要。例如,可以使用以下 CSS。

table{
transform:rotate(-90deg);
margin-left:-10rem;
margin-top:6rem;
}

(或)

 table {
position:absolute;
bottom:3rem;
left:0;
transform:rotate(-90deg)
}

<!DOCTYPE html>
<html>
<head>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />

<style>
table{
transform:rotate(-90deg);
position:absolute;
bottom:3rem;
left:0;
}
</style>
</head>
<body>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Larry</td>
<td>the Bird</td>
<td>@twitter</td>
</tr>
</tbody>
</table>
</body>
</html>

关于html - 在 HTML/CSS 中垂直显示表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65474337/

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