gpt4 book ai didi

html - 带有 float 和动态边的 Bootstrap 表格单元格

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

过去几天我一直在努力让我的 Bootstrap 表看起来像我想要的那样。

我只是无法让它工作。

我想要的是第一个 td 必须是动态宽度,具有最大宽度和最小宽度,因为值介于 1 和 9999 之间。数字必须右对齐。减号按钮应左对齐。所有这些都必须在同一条线上。

中间的单元格也必须有动态宽度。但是 text-overflow: ellipsis; 我也开始工作了。最后一个 td 具有固定宽度。

这是我想要的一些示例。

第一个 td 的动态侧和第二个 td 的折叠: dynamic side of first td dynamic side of first td collapsing in second td

我试过很多东西。例如。我试图用单元格末尾的减号按钮制作一个固定宽度的“clearfix”。仅当单元格中的值为 9999 而不是 1 时才有效。

这是它现在的样子: screenshot now

这里有一个例子:http://www.bootply.com/jNx2MJrNG0

代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<style>
.cartTable thead {
color: #333;
background-color: #f5f5f5;
border-color: #ddd;
}

.cartTable th {
border-bottom: 1px solid #ddd;
font-weight: normal;
}

.cartTable > tbody > tr > td {
vertical-align: middle;
font-size: 18px;
font-weight: bold;
}

.cartTable th:first-child,
.cartTable td:first-child {
padding-left: 15px;
}

.cartTable .quantityColumn {
white-space: nowrap;
width: 10px;
min-width: 59px;
max-width: 114px;
text-align: right;
padding: 8px 0;
}
/*.minusDiv {
clear: both;
}*/
.quantityColumn .minusToLeft {
/*display: inline-block;*/
/*text-align: right;*/
float: left;
}

.minusToRight {
width: 40px;
display: inline-block;
clear: both;
}

.quantityColumn .btnMinus {
margin-left: 0;
margin-right: 5px;
}

.quantityColumn .btnPlus {
margin-left: 5px;
}

.quantityColumnDiv {
min-width: 59px;
max-width: 114px;
}

.cartTable .nameColumn {
max-width: 80px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.cartTable .btnColumn {
width: 105px;
padding-left: 0;
padding-right: 15px;
/*text-align: right;*/
}

@media (max-width:767px) {
.cartTable .quantityColumn {
padding: 8px;
}

.cartTable .btnColumn {
width: 50px;
}
}

.btnSearch {
margin-right: 5px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-6">
<div class="panel panel-default">
<table class="table cartTable">
<thead>
<tr>
<th>Quantity</th>
<th>Product</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td class="quantityColumn">
<span class="minusToLeft">
<button type="button" class="btn btn-danger btn-xs hidden-xs btnMinus">
<span class="glyphicon glyphicon-minus"></span>
</button>
</span>
1
<button type="button" class="btn btn-success btn-xs hidden-xs btnPlus">
<span class="glyphicon glyphicon-plus"></span>
</button>
</td>
<td class="nameColumn">ALongTextToCollaps</td>
<td class="btnColumn">
<button type="button" class="btn btn-info btnSearch">
<span class="glyphicon glyphicon-search"></span>
</button>
<button type="button" class="btn btn-danger">
<span class="glyphicon glyphicon-trash"></span>
</button>
</td>
</tr>
<tr>
<td class="quantityColumn">

<span class="minusToLeft">
<button type="button" class="btn btn-danger btn-xs hidden-xs btnMinus">
<span class="glyphicon glyphicon-minus"></span>
</button>
</span>

9999
<button type="button" class="btn btn-success btn-xs hidden-xs btnPlus">
<span class="glyphicon glyphicon-plus"></span>
</button>

</td>
<td class="nameColumn">test cake</td>
<td class="btnColumn">
<button type="button" class="btn btn-info btnSearch">
<span class="glyphicon glyphicon-search"></span>
</button>
<button type="button" class="btn btn-danger">
<span class="glyphicon glyphicon-trash"></span>
</button>
</td>
</tr>

</tbody>
</table>
</div>
</div>

</div>
</div>
</body>
</html>

我如何让第一个 td 的内容保持在同一行上,减号按钮向左,这样数字就彼此右对齐并且列的宽度仍然是动态的?

最佳答案

你有两个选择:

  • .cartTable quantityColumn 中的 width 增加到 120px(或者只是将其调整为数量列的最大尺寸)以给它更多空间
  • 我更喜欢有另外两列,一列用于-,一列用于+

关于html - 带有 float 和动态边的 Bootstrap 表格单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39466189/

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