asp.net 我怎样才能保持一个20列的HTML表格的单元格的内容在一行和 Package 特定的宽度

ut6juiuv  于 2023-08-08  发布在  .NET
关注(0)|答案(2)|浏览(110)

我在一个单元格中有很长的数据,我需要把数据放在一行中的特定宽度,其余的则 Package 到下一行。我已经能够使它在一行中,但不能在特定宽度后用td{word-wrap:断字},可能是因为td{white-space:我不想在这个词的中间打个结。
样式和HTML结构将用于在ERP中创建表。
我有以下CSS:

``
th { /* header cell */
    border-bottom: 2px solid #EB9486;
    position: sticky;
    top: 0;
    background-color: #F9F8F8;
}
td {  /*body cell */
    white-space: nowrap;
    border: 1px solid black;
}

/*Adds scroll to the table*/
.table-container {
    overflow: auto;
    height: 300px;
}
``

``
<div class="table-container">
    <table>
        <thead>
            <tr>
                <th class="FirstHeader">Name</th>
                <th class="SecondHeader">Job</th>
                <th>Salary</th>
                <th>Name</th>
                <th>Job</th>
                <th>Salary</th>
                <th>Name</th>
                <th>Job</th>
                <th>Salary</th>
                <th>Name</th>
                <th>Job</th>
                <th>Salary</th>
                <th>Name</th>
                <th>Job</th>
                <th>Salary</th>
                <th>Name</th>
                <th>Job</th>
                <th>Salary</th>
                <th>Name</th>
                <th>Job</th>
                
            </tr>
        </thead>

        <tbody>
            <tr class="FirstColumn">
                <td>Olivia Saturday</td>
                <td>Senior Data Engineer</td>
                <td>$320,000</td>
                <td>David Smith</td>
                <td>Manager Strategic Finance Manager Strategic Finance     Manager11</td>
                <td>$180,000</td>
                <td>David Smith</td>
                <td> Manager Strategic Finance Manager Strategic Finance Manager</td>
                <td>$180,000</td>
                <td>David Smith</td>
                <td> Manager Strategic Finance Manager Strategic Finance Manager</td>
                <td>$180,000</td>
                <td>David Smith</td>
                <td> Manager Strategic Finance Manager Strategic Finance Manager</td>
                <td>$180,000</td>
                <td>David Smith</td>
                <td> Manager Strategic Finance Manager Strategic Finance Manager</td>
                <td>$180,000</td>
                <td>David Smith</td>
                <td>Manager Strategic Finance Manager Strategic Finance Manager</td>
                <td>$180,000</td>
                <td>David Smith</td>
                <td>Manager Strategic Finance Manager Strategic Finance Manager</td>
                <td>$180,000</td>
            </tr>

            <tr class="SecondColumn">
                <td>David Smith</td>
                <td> Manager Strategic Finance Manager Strategic Finance Manager</td>
                <td>$180,000</td>
            </tr>

            <tr>
                <td>Margaret Mills</td>
                <td>Lead Software Engineer</td>
                <td>$250,000</td>
            </tr>

            <tr>
                <td>Paul Brown</td>
                <td>Digital Content Writer</td>
                <td>$145,000</td>
            </tr>

            <tr>
                <td>Stephanie Tavartkiladze</td>
                <td>Digital Project Manager</td>
                <td>$250,000</td>
            </tr>

            <tr>
                <td>Olivia Saturday</td>
                <td>Senior Data Engineer</td>
                <td>$320,000</td>
            </tr>

            <tr>
                <td>David Smith</td>
                <td>Strategic Finance Manager</td>
                <td>$180,000</td>
            </tr>

            <tr>
                <td>Margaret Mills</td>
                <td>Lead Software Engineer</td>
                <td>$250,000</td>
            </tr>

            <tr>
                <td>Paul Brown</td>
                <td>Digital Content Writer</td>
                <td>$145,000</td>
            </tr>

            <tr>
                <td>Stephanie Tavartkiladze</td>
                <td>Digital Project Manager</td>
                <td>$250,000</td>
            </tr>

            <tr>
                <td>Olivia Saturday</td>
                <td>Senior Data Engineer</td>
                <td>$320,000</td>
            </tr>

            <tr>
                <td>David Smith</td>
                <td>Strategic Finance Manager</td>
                <td>$180,000</td>
            </tr>

            <tr>
                <td>Margaret Mills</td>
                <td>Lead Software Engineer</td>
                <td>$250,000</td>
            </tr>

            <tr>
                <td>Paul Brown</td>
                <td>Digital Content Writer</td>
                <td>$145,000</td>
            </tr>

            <tr>
                <td>Stephanie Tavartkiladze</td>
                <td>Digital Project Manager</td>
                <td>$250,000</td>
            </tr>

            <tr>
                <td>Olivia Saturday</td>
                <td>Senior Data Engineer</td>
                <td>$320,000</td>
            </tr>

            <tr>
                <td>David Smith</td>
                <td>Strategic Finance Manager</td>
                <td>$180,000</td>
            </tr>

            <tr>
                <td>Margaret Mills</td>
                <td>Lead Software Engineer</td>
                <td>$250,000</td>
            </tr>

            <tr>
                <td>Paul Brown</td>
                <td>Digital Content Writer</td>
                <td>$145,000</td>
            </tr>

            <tr>
                <td>Stephanie Tavartkiladze</td>
                <td>Digital Project Manager</td>
                <td>$250,000</td>
            </tr>
        </tbody>
    </table>
</div>
``

字符串
如果我不使用td{white-space: nowrap;},由于列的数量,数据会被 Package 。也许我应该改变HTML。我不知道我不知道我糊涂了。请帮帮我

wkyowqbh

wkyowqbh1#

不太确定我是否理解了这个问题,但是你可以在td标签中使用nowrap关键字:

选项一:

<td nowrap>content</td>

字符串
如果你需要一个固定的宽度,你也可以创建一个类...

选项二:

联系我们

<td class="fixed-width">content</td>


css:

.fixed-width { width: 200px;}


或执行内联样式

选项三:

<td style="width: 200px;">content</td>

mnemlml8

mnemlml82#

基本上我认为你的问题源于一个失踪的专栏,也许这是扔你?
下面的代码应该会给予你一个没有换行的滚动表。如果Show_Empty_Cells是Experiment with it,尝试更改样式并查看更改后的效果,那么可能空(合并)单元格并不是真正必要的。

<%@ Page Language="VB" %>

<!DOCTYPE html>

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title></title>
   <style>
   /*CONTAINER*/
   .mytablecontainer {
       margin-left: auto;
       margin-right: auto;
       width: 90%;
       overflow: scroll; /* SCROLLING */
       height: 300px;
   }
   /*TABLE*/
   .mytabletable {
      border-collapse: collapse;
      border: 1px solid #EB9486;
      height: 300px;
      background-color: #FFFFFF;
   }
   th { /* header cell */
       position: sticky;
       top: 0;
       padding: 8px;
       background-color: #F9F8F8;
       border: 1px solid black;
   }
   td 
   {  /*body cell */
      text-align: left;
      vertical-align: top;
       border: 1px solid black;
   }
   .textcolumn
   {
      text-align: left;
      vertical-align: top;
      padding: 8px;
      border: 1px solid black;
      white-space: nowrap;
   }
   .moneycolumn
   {
      text-align: right;
      vertical-align: top;
      padding: 8px;
      border: 1px solid black;
      white-space: nowrap;
   }

   </style>
</head>
<body>

<form id="form1" runat="server">
   <div class="mytablecontainer">
      <table class="mytabletable">
         <!-- Headers -->
         <thead>
            <tr>
               <th>Name</th>
               <th>Job</th>
               <th>Salary</th>
               <th>Name</th>
               <th>Job</th>
               <th>Salary</th>
               <th>Name</th>
               <th>Job</th>
               <th>Salary</th>
               <th>Name</th>
               <th>Job</th>
               <th>Salary</th>
               <th>Name</th>
               <th>Job</th>
               <th>Salary</th>
               <th>Name</th>
               <th>Job</th>
               <th>Salary</th>
               <th>Name</th>
               <th>Job</th>
               <th>Salary</th> <!-- This column was missing? -->
            </tr>
         </thead>
         <!-- Body -->
         <tbody>
            <tr> <!-- First ROW not first column -->
               <td class="textcolumn">Olivia Saturday</td>
               <td class="textcolumn">Senior Data Engineer</td>
               <td class="MoneyColumn">$320,000</td>
               <td class="textcolumn">David Smith</td>
               <td class="textcolumn">Manager Strategic Finance Manager Strategic Finance     Manager11</td>
               <td class="moneycolumn">$180,000</td>
               <td class="textcolumn">David Smith</td>
               <td class="textcolumn"> Manager Strategic Finance Manager Strategic Finance Manager</td>
               <td class="moneycolumn">$180,000</td>
               <td class="textcolumn">David Smith</td>
               <td class="textcolumn"> Manager Strategic Finance Manager Strategic Finance Manager</td>
               <td class="moneycolumn">$180,000</td>
               <td class="textcolumn">David Smith</td>
               <td class="textcolumn"> Manager Strategic Finance Manager Strategic Finance Manager</td>
               <td class="moneycolumn">$180,000</td>
               <td class="textcolumn">David Smith</td>
               <td class="textcolumn"> Manager Strategic Finance Manager Strategic Finance Manager</td>
               <td class="moneycolumn">$180,000</td>
               <td class="textcolumn">David Smith</td>
               <td class="textcolumn">Manager Strategic Finance Manager Strategic Finance Manager</td>
               <td class="moneycolumn">$180,000</td>
            </tr><tr>
               <td class="textcolumn">David Smith</td>
               <td class="textcolumn"> Manager Strategic Finance Manager Strategic Finance Manager</td>
               <td class="moneycolumn">$180,000</td>
               <td colspan="18">&nbsp;</td>
            </tr><tr>
               <td class="textcolumn">Margaret Mills</td>
               <td class="textcolumn">Lead Software Engineer</td>
               <td class="moneycolumn">$250,000</td>
               <td colspan="18">&nbsp;</td>
            </tr><tr>
               <td class="textcolumn">Paul Brown</td>
               <td class="textcolumn">Digital Content Writer</td>
               <td class="moneycolumn">$145,000</td>
               <td colspan="18">&nbsp;merge all contigous empty cells into one</td>
            </tr><tr>
               <td class="textcolumn">Stephanie Tavartkiladze</td>
               <td class="textcolumn">Digital Project Manager</td>
               <td class="moneycolumn">$250,000</td>
               <td colspan="18">&nbsp;</td>
            </tr><tr>
               <td class="textcolumn">Charly Boy</td>
               <td class="textcolumn">King of the UK</td>
               <td class="moneycolumn">Unspecified</td>
               <td colspan="18">&nbsp;</td>
            </tr>
         </tbody>
      </table>
   </div>
</form>
</body>
</html>

字符串

相关问题