gpt4 book ai didi

html - 如何让一个表适合它的父容器?

转载 作者:行者123 更新时间:2023-11-28 07:38:35 27 4
gpt4 key购买 nike

我有一个超出其父容器的表。我怎样才能让它适应它的 parent ?我尝试关注 http://www.imaputz.com/cssStuff/bigFourVersion.html但是我的专栏没有排列时遇到了问题。有人建议将 block 更改为行组,但现在即使我对高度进行硬编码也无法显示滚动条。

这是一个 fiddle :http://jsfiddle.net/bwdc78tr/1/

和 HTML

<body>

<header id='header'>

<br>
<form id='reload' name="Actions" action="Viewer.php" method="post">
<div id='LookupSection'>
Whole Number

<input type="text" id='WholeNumber' name="WholeNumber" title="Enter the whole number here">
<img id='dropDownButton' src="Images/ComboDropdown.png" title="Click to drop down a partial whole number list based on the current entry" onclick="toggleDropdown()"/>

<div id='WholeNumberDiv'>
<table id='wholeNumberDropdown'>
</table>
</div>

</div>
</form>

</header>

<div id="sidebar">
<a href="" onclick="window.location.reload();">Clear</a><br>
<a href="" onclick="gatherImages();">Gather Images</a><br>
</div>

<div id="content">

<Table id="ImageDataTable">
<thead>
<tr style="position:relative;display:block">
<th class='ImageDataCell' style="width:200px;">Whole Nbr</div>
<th class='ImageDataCell' style="width:50px;">Type</th>
<th class='ImageDataCell' style="width:50px;">Size</th>
<th class='ImageDataCell' style="width:100px;">Revision</th>
<th class='ImageDataCell' style="width:100px;">Other Nbr</th>
<th class='ImageDataCell' style="width:50px;">Sheet Nbr</th>
<th class='ImageDataCell' style="width:50px;">Of Sheets</th>
<th class='ImageDataCell' style="width:50px;">Frame Nbr</th>
<th class='ImageDataCell' style="width:50px;">Of Frames</th>
<th class='ImageDataCell' style="width:250px;">Doc Title</th>
<th class='ImageDataCell' style="width:100px;">Volume</th>
<th class='ImageDataCell' style="width:50px;">Note</th>
<th class='ImageDataCell' style="width:50px;">Prnt</th>
<th class='ImageDataCell' style="width:50px;">Obs</th>
<th class='ImageDataCell' style="width:100px;">Acquire Date</th>
<th class='ImageDataCell' style="width:150px;">Source</th>
<th class='ImageDataCell' style="width:100px;">Base Doc</th>
<th class='ImageDataCell' style="width:100px;">Acc Doc Nbr</th>
<th class='ImageDataCell' style="width:100px;">CommonSubDirectory</th>
</tr>
</thead>
<tbody style="display:block;overflow:auto">

<tr>

<td class="ImageDataCell" width="200px">

SS1026

</td>
<td class="ImageDataCell" width="50px">

DD

</td>
<td class="ImageDataCell" width="50px">

A

</td>
<td class="ImageDataCell" width="100px">

2

</td>
<td class="ImageDataCell" width="100px"></td>
<td class="ImageDataCell" width="50px">

10

</td>
<td class="ImageDataCell" width="50px">

10

</td>
<td class="ImageDataCell" width="50px">

1

</td>
<td class="ImageDataCell" width="50px">

1

</td>
<td class="ImageDataCell" width="250px">

JOGGLING OF ALUMINUM ALLOY EXTRUDED

</td>
<td class="ImageDataCell" width="100px">

89576

</td>
<td class="ImageDataCell" width="50px"></td>
<td class="ImageDataCell" width="50px">

No

</td>
<td class="ImageDataCell" width="50px">

No

</td>
<td class="ImageDataCell" width="100px">

2004-07-15

</td>
<td class="ImageDataCell" width="150px">

DSCR

</td>
<td class="ImageDataCell" width="100px">

Yes

</td>
<td class="ImageDataCell" width="100px"></td>
<td class="ImageDataCell" width="100px">

\CDVolumes

</td>

</tr>
<tr>

<td class="ImageDataCell" width="200px">

SS1026

</td>
<td class="ImageDataCell" width="50px">

DD

</td>
<td class="ImageDataCell" width="50px">

A

</td>
<td class="ImageDataCell" width="100px">

2

</td>
<td class="ImageDataCell" width="100px"></td>
<td class="ImageDataCell" width="50px">

10

</td>
<td class="ImageDataCell" width="50px">

10

</td>
<td class="ImageDataCell" width="50px">

1

</td>
<td class="ImageDataCell" width="50px">

1

</td>
<td class="ImageDataCell" width="250px">

JOGGLING OF ALUMINUM ALLOY EXTRUDED

</td>
<td class="ImageDataCell" width="100px">

89576

</td>
<td class="ImageDataCell" width="50px"></td>
<td class="ImageDataCell" width="50px">

No

</td>
<td class="ImageDataCell" width="50px">

No

</td>
<td class="ImageDataCell" width="100px">

2004-07-15

</td>
<td class="ImageDataCell" width="150px">

DSCR

</td>
<td class="ImageDataCell" width="100px">

Yes

</td>
<td class="ImageDataCell" width="100px"></td>
<td class="ImageDataCell" width="100px">

\CDVolumes

</td>

</tr><tr>

<td class="ImageDataCell" width="200px">

SS1026

</td>
<td class="ImageDataCell" width="50px">

DD

</td>
<td class="ImageDataCell" width="50px">

A

</td>
<td class="ImageDataCell" width="100px">

2

</td>
<td class="ImageDataCell" width="100px"></td>
<td class="ImageDataCell" width="50px">

10

</td>
<td class="ImageDataCell" width="50px">

10

</td>
<td class="ImageDataCell" width="50px">

1

</td>
<td class="ImageDataCell" width="50px">

1

</td>
<td class="ImageDataCell" width="250px">

JOGGLING OF ALUMINUM ALLOY EXTRUDED

</td>
<td class="ImageDataCell" width="100px">

89576

</td>
<td class="ImageDataCell" width="50px"></td>
<td class="ImageDataCell" width="50px">

No

</td>
<td class="ImageDataCell" width="50px">

No

</td>
<td class="ImageDataCell" width="100px">

2004-07-15

</td>
<td class="ImageDataCell" width="150px">

DSCR

</td>
<td class="ImageDataCell" width="100px">

Yes

</td>
<td class="ImageDataCell" width="100px"></td>
<td class="ImageDataCell" width="100px">

\CDVolumes

</td>

</tr><tr>

<td class="ImageDataCell" width="200px">

SS1026

</td>
<td class="ImageDataCell" width="50px">

DD

</td>
<td class="ImageDataCell" width="50px">

A

</td>
<td class="ImageDataCell" width="100px">

2

</td>
<td class="ImageDataCell" width="100px"></td>
<td class="ImageDataCell" width="50px">

10

</td>
<td class="ImageDataCell" width="50px">

10

</td>
<td class="ImageDataCell" width="50px">

1

</td>
<td class="ImageDataCell" width="50px">

1

</td>
<td class="ImageDataCell" width="250px">

JOGGLING OF ALUMINUM ALLOY EXTRUDED

</td>
<td class="ImageDataCell" width="100px">

89576

</td>
<td class="ImageDataCell" width="50px"></td>
<td class="ImageDataCell" width="50px">

No

</td>
<td class="ImageDataCell" width="50px">

No

</td>
<td class="ImageDataCell" width="100px">

2004-07-15

</td>
<td class="ImageDataCell" width="150px">

DSCR

</td>
<td class="ImageDataCell" width="100px">

Yes

</td>
<td class="ImageDataCell" width="100px"></td>
<td class="ImageDataCell" width="100px">

\CDVolumes

</td>

</tr><tr>

<td class="ImageDataCell" width="200px">

SS1026

</td>
<td class="ImageDataCell" width="50px">

DD

</td>
<td class="ImageDataCell" width="50px">

A

</td>
<td class="ImageDataCell" width="100px">

2

</td>
<td class="ImageDataCell" width="100px"></td>
<td class="ImageDataCell" width="50px">

10

</td>
<td class="ImageDataCell" width="50px">

10

</td>
<td class="ImageDataCell" width="50px">

1

</td>
<td class="ImageDataCell" width="50px">

1

</td>
<td class="ImageDataCell" width="250px">

JOGGLING OF ALUMINUM ALLOY EXTRUDED

</td>
<td class="ImageDataCell" width="100px">

89576

</td>
<td class="ImageDataCell" width="50px"></td>
<td class="ImageDataCell" width="50px">

No

</td>
<td class="ImageDataCell" width="50px">

No

</td>
<td class="ImageDataCell" width="100px">

2004-07-15

</td>
<td class="ImageDataCell" width="150px">

DSCR

</td>
<td class="ImageDataCell" width="100px">

Yes

</td>
<td class="ImageDataCell" width="100px"></td>
<td class="ImageDataCell" width="100px">

\CDVolumes

</td>

</tr><tr>

<td class="ImageDataCell" width="200px">

SS1026

</td>
<td class="ImageDataCell" width="50px">

DD

</td>
<td class="ImageDataCell" width="50px">

A

</td>
<td class="ImageDataCell" width="100px">

2

</td>
<td class="ImageDataCell" width="100px"></td>
<td class="ImageDataCell" width="50px">

10

</td>
<td class="ImageDataCell" width="50px">

10

</td>
<td class="ImageDataCell" width="50px">

1

</td>
<td class="ImageDataCell" width="50px">

1

</td>
<td class="ImageDataCell" width="250px">

JOGGLING OF ALUMINUM ALLOY EXTRUDED

</td>
<td class="ImageDataCell" width="100px">

89576

</td>
<td class="ImageDataCell" width="50px"></td>
<td class="ImageDataCell" width="50px">

No

</td>
<td class="ImageDataCell" width="50px">

No

</td>
<td class="ImageDataCell" width="100px">

2004-07-15

</td>
<td class="ImageDataCell" width="150px">

DSCR

</td>
<td class="ImageDataCell" width="100px">

Yes

</td>
<td class="ImageDataCell" width="100px"></td>
<td class="ImageDataCell" width="100px">

\CDVolumes

</td>

</tr>
</tbody>

</Table>

</div>

<footer>

<br>
</footer>

</body>
</html>

我似乎找不到任何网页来解释为什么有时会扩展以及何时决定不扩展。我所看到的一切都是简单的解释,在现实世界中是行不通的。如果有人可以提出可能有帮助的好的搜索词,我将不胜感激。

最佳答案

表格单元格会根据内容扩展到超出您指定的大小。如果单个单词的宽度大于 100px,则单元格将扩展到更宽单词的宽度,除非您采取措施将其截断。相反,我建议您不要尝试为表格单元格施加像素宽度,而是让 HTML 表格像往常一样呈现。宽度以这种方式照顾自己。只要您不将表格的任何部分更改为 display:block header 将始终与正文单元格对齐。

创建滚动表体不是一件容易的事,但绝对可以做到。我过去通过创建一个普通表格解决了这个问题(表格标记中的任何地方都没有 display:block,事实上,如果没有内联 CSS,这样做会更容易)。使用 overflow-y:scroll 将原始表放在一个 div 中.

然后,使用一些脚本,我创建了表格标题部分的克隆并将其分层放置在滚动 DIV 的顶部。 (您需要为克隆的表格添加一些右边距,以考虑垂直滚动条的宽度)。最后,我用 overflow-x:scroll 将整个组合放在一个 DIV 中。这样如果表格对于显示而言太宽,它可以水平滚动。

这绕过了改变表格组件自然显示模式的愚弄。它还可以更轻松地适应浏览器调整大小等,如果您让表格来管理它自己的列大小,特别是如果您将表格及其克隆的标题与 colgroup 组合以设置百分比列宽。尽量不要将内联 CSS 应用于您的单个表格单元格,因为这将成为管理的噩梦。

所以在概念上,HTML 看起来像这样:

<div class="tableouter">
<div class="tableinner">
<table>
<colgroup>
<col style="10%"></col> <--- repeat for each column and adjust width to taste
</colgroup>
<thead>
...
</thead>
<tbody>
...
</tbody>
</table>
</div>
<table class="headerclone" /> (clone of header portion, including colgroup)
</div>

和基本的 CSS:

.tableouter {
position: relative;
overflow-x:scroll;
}

.headerclone {
position: absolute;
top: 0;
left: 0;
margin-right: 16px; <-- This accounts for the vertical scroll bar. I needed to use some script to determine the exact size of the scrollbar for each browser. Apply this value as inline CSS in your cloning script.
}

.tableinner {
height: 400px; <-- this determines the height of the scrolling container.
overlfow-y: scroll
}

现在这掩盖了相当多的细节......为了使您的克隆脚本更可靠,您可能想要测量实际列的宽度,而不是在克隆的 colgroup 中应用显式像素宽度。 .然后你可能想放一个观察者来调整克隆列的大小,如果浏览器被调整等等等等。

关于html - 如何让一个表适合它的父容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31080751/

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