简体   繁体   English

我想根据页面宽度将一个很长的 HTML 表格行拆分为多行

[英]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 应用于tablebutton元素来实现这一点。 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 trtd标签。

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.

相关问题 我想删除从表中选择的多行,dom正在更改,但它正在从html页面的最后一行删除行 - I want to delete multiple rows selected from table, dom is changing but it is deleting rows from last on html page 我想根据情况更改表格的行颜色 - I want to change row colors of a table according to the condition 我想创建HTML页面,该页面需要通过按行和列数提供输入来显示表的行和列 - I want to create HTML page which needs to show table rows and column by giving inputs by number of rows and columns 用于HTML的JavaScript ::我想为每个表行显示多个数据 - JavaScript for HTML :: I want to show multiple data into multiple filed for each Table Row 如何根据表格的宽度(而不是整个页面的宽度)在表格上方放置标题? - How can I center a header above a table according to the table's width (not the entire page's width)? 将一行单元格拆分为多行 - Split a row of cells into multiple rows 我想根据less或css中的HTML lang属性更改width的值 - I want to change the value of width according to HTML lang attribute in less or css 我想根据正则表达式和条件为 HTML 表行着色 - I want to color HTML table rows based on regex and condition 我想将行数据动态添加到 HTML 表 - I want to dynamically add row data to HTML Table 我在div中有一张长桌子,当我滚动桌子时,我想看看它会惯性地移动HTML - I have a long table in a div, when I scroll the table, I want to see it moves inertially HTML
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM