[英]I want to split a long HTML table row into multiple rows according to the page width
I am using AngularJS to generate a row of Material buttons in an HTML table.我正在使用 AngularJS 在 HTML 表格中生成一行 Material 按钮。 The selected button is highlighted.
所选按钮突出显示。
<tr>
<td ng-click="pbmain.selectWC(WC.WCName)" ng-repeat="WC in pbmain.WCList">
md-button(ng-class="WC.WCName == pbmain.selectedWCName ? 'md-raised md-primary' : 'md-raised'") {{WC.WCName}}
</td>
</tr>
The number of buttons and text on the buttons can be quite long and the row is often 2-3 times the width of the browser window.按钮的数量和按钮上的文本可能会很长,并且一行通常是浏览器窗口宽度的 2-3 倍。 For the moment, I scroll across but I am looking for a more user-friendly solution.
目前,我滚动浏览,但我正在寻找更用户友好的解决方案。
I would like to be able to split the row automatically, according to the page width - something like the example below.我希望能够根据页面宽度自动拆分行 - 类似于下面的示例。
You can achieve this by applying proper CSS to table
and button
elements.您可以通过将适当的 CSS 应用于
table
和button
元素来实现这一点。 No need to split a row into multiple rows.无需将一行拆分为多行。
Example:例子:
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span><span>TEST</span>
</td>
</tr>
CSS CSS
table {
table-layout: fixed;
width: 100%
}
span {
border: 1px solid black;
margin: 10px;
width: 100px;
display: inline-block;
}
Have a look at this fiddle .看看这个小提琴。
I have no idea how to accomplish this easily within a table.我不知道如何在表格中轻松完成此操作。 Maybe you could make some pre-work on your array to make it two-dimensional and then
ng-repeat
tr
and td
tags as well.也许你可以对你的数组做一些预先工作,使它成为二维的,然后还有
ng-repeat
tr
和td
标签。
My solution would be a clean grid system with Bootstrap .我的解决方案是使用 Bootstrap 构建一个干净的网格系统。
With this you can achieve a fully responsive screen.有了这个,您可以实现完全响应的屏幕。 If you do not need to stick with a table system, then you should consider this.
如果您不需要坚持使用表系统,那么您应该考虑这一点。
Well, I was searching by splitting rows into multiple rows and I got here.好吧,我通过将行分成多行进行搜索,然后我到了这里。
It seems that your problem could be better solver by using display: inline-block;
使用
display: inline-block;
似乎可以更好地解决您的问题display: inline-block;
for every button.对于每个按钮。
However, if you really need a table for other purpose check at this next approach .但是,如果您真的需要一个用于其他目的的表,请查看下一个方法。 It would redrawn your linear tabular long table into a multilined table by only using css.
它将仅使用 css 将您的线性表格长表重新绘制为多行表。 Than you can play around with your screen size.
比你可以玩你的屏幕尺寸。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.