gpt4 book ai didi

html - 正确对齐表格单元格中元素之间的间距

转载 作者:太空宇宙 更新时间:2023-11-04 02:59:19 25 4
gpt4 key购买 nike

我试过搜索,但我不知道该怎么调用它。我正在尝试完成这张图片左侧的内容:

Table

但是,当我更改页面宽度时,它会折叠并导致意外行为。

我正在使用 margin-left: 50px; float:left 用于插入符号,margin-right: 50px 用于文本。

http://embed.plnkr.co/v68tw85oYqEeBmfCreD5/preview

<!DOCTYPE html>
<html>

<head>
<link data-require="bootstrap-css@*" data-semver="3.3.1" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />
<link data-require="font-awesome@*" data-semver="4.3.0" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" />
<script data-require="jquery@*" data-semver="2.1.4" src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>

<body>
<table class="table table-bordered text-center">
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Money</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td><i class="fa fa-caret-up" style="float:left; margin-left: 50px"></i><span style="margin-right: 100px">2332</span></td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td style="width: 300px"><i class="fa fa-caret-down" style="float:left; margin-left: 50px"></i><span style="margin-right: 100px">1.2</span></td>
</tr>
<tr>
<th scope="row">3</th>
<td>Larry</td>
<td>the Bird</td>
<td><i class="fa fa-caret-down" style="float:left; margin-left: 50px"></i><span style="margin-right: 100px">1.2</span></td>
</tr>
</tbody>
</table>
</body>

</html>

有没有更好的不折叠的方法?

最佳答案

尝试以下操作:http://jsfiddle.net/jLod5cv9/ .单元格的每个元素都设置为 inline-blockwhite-space: nowrap 声明应该将它们放在一起。

HTML:

<table>
<tr><td class = "up" data-number = "3"></td></tr>
<tr><td class = "down" data-number = "-55"></td></tr>
<tr><td class = "down" data-number = "-44"></td></tr>
<tr><td class = "up" data-number = "1"></td></tr>
<tr><td class = "up" data-number = "65"></td></tr>
</table>

CSS:

table {
border-collapse: collapse;
}

table td {
white-space: nowrap;
border: 1px solid #ccc;
padding: 5px 10px;
color: green;
}

table td.down {
color: red;
}

table td:after {
content: attr(data-number);
display: inline-block;
font: normal 12px/1 Sans-Serif;
width: 25px;
text-align: center;
}

table td:before {
content: "";
display: inline-block;
border-style: solid;
border-width: 0px 4px 5px 4px;
border-color: transparent transparent green transparent;
margin-right: 15px;
}

table td.down:before {
border-width: 5px 4px 0 4px;
border-color: red transparent transparent transparent;
}

关于html - 正确对齐表格单元格中元素之间的间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31594886/

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