gpt4 book ai didi

HTML/CSS - 高度固定的容器中表格单元格的高度不一致

转载 作者:行者123 更新时间:2023-11-28 13:24:30 24 4
gpt4 key购买 nike

我有一个使用 HTML/CSS 设置的表格,它位于 UL 的 LI 元素内,该 UL 元素被转换为 Accordion 。问题是,当 LI 元素动画到特定高度时,它会改变表格单元格的高度,使最后一个单元格从 View 中隐藏。

如果从父 LI 元素中移除固定高度,则不存在此问题,但这是 Accordion 功能所必需的。有没有办法确保单元格始终具有相同的高度,而不管父容器的高度属性如何?

我已经设置了以下 JS Fiddle 来显示问题。默认情况下,它运行 Accordion 功能。如果你把它拿掉,你可以看到表格是在父容器中添加高度之前的样子。

由于 Accordion 默认关闭所有元素,您必须单击显示“表格”的标题栏才能打开表格并查看内容。

http://jsfiddle.net/dsQtP/2/

下面是给希望看到它的人的代码:

HTML:

<ul class="accordion">
<li>
<h3>Table</h3>
<span class="accordionContent">
<table>
<tr class="tableHeader">
<td class="first">HEADER</td>
<td>TITLE<span>SUBTITLE</span>

</td>
<td>TITLE<span>SUBTITLE</span>

</td>
<td class="last">TITLE<span>SUBTITLE</span>

</td>
</tr>
<tr class="tableRow_odd">
<td class="first">ACTIVE ITEM</td>
<td>ACTIVE ITEM</td>
<td>ACTIVE ITEM</td>
<td class="last">ACTIVE ITEM</td>
</tr>
<tr class="tableRow_even">
<td class="first"></td>
<td>ACTIVE ITEM</td>
<td>ACTIVE ITEM</td>
<td class="last"><span class="unavailable">INACTIVE ITEM</span>

</td>
</tr>
<tr class="tableRow_odd">
<td class="first"></td>
<td>ACTIVE ITEM</td>
<td><span class="unavailable">INACTIVE ITEM</span>

</td>
<td class="last"><span class="unavailable">INACTIVE ITEM</span>

</td>
</tr>
<tr class="tableRow_even">
<td class="first"></td>
<td>ACTIVE ITEM</td>
<td><span class="unavailable">INACTIVE ITEM</span>

</td>
<td class="last"><span class="unavailable">INACTIVE ITEM</span>

</td>
</tr>
<tr class="tableRow_odd">
<td class="first"></td>
<td>ACTIVE ITEM</td>
<td><span class="unavailable">INACTIVE ITEM</span>

</td>
<td class="last"><span class="unavailable">INACTIVE ITEM</span>

</td>
</tr>
</table> <span class="itemOverlay"></span></span>
</li>
</ul>

CSS:

body { padding: 15px }
/* Class Setups */


.accordion {


width: 500px;


margin: 0 auto;


overflow: hidden;


-webkit-border-radius: 5px;


-khtml-border-radius: 5px;


-moz-border-radius: 5px;


-o-border-radius: 5px;


border-radius: 5px;


}


.accordion li {


overflow: hidden;


position: relative;


}


.accordion li h3 {


color: #fff;


font-weight: 100;


padding: 7px 0 7px 12px;


border-bottom: 1px solid #4d82ae;


cursor: pointer;


font-size: 19px;


background: #5d8ebd;


/* Old browsers */


background: -moz-linear-gradient(top, #5d8ebd 0%, #659ecb 100%);


/* FF3.6+ */


background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #5d8ebd), color-stop(100%, #659ecb));


/* Chrome,Safari4+ */


background: -webkit-linear-gradient(top, #5d8ebd 0%, #659ecb 100%);


/* Chrome10+,Safari5.1+ */


background: -o-linear-gradient(top, #5d8ebd 0%, #659ecb 100%);


/* Opera 11.10+ */


background: -ms-linear-gradient(top, #5d8ebd 0%, #659ecb 100%);


/* IE10+ */


background: linear-gradient(to bottom, #5d8ebd 0%, #659ecb 100%);


/* W3C */


filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#5d8ebd', endColorstr='#659ecb', GradientType=0);


/* IE6-9 */


}


.accordionContent a {


display: block;


position: relative;


z-index: 999;


}


.accordionContent > * {


padding: 15px;


width: 100%;


height: 100%;


position: relative;


}


.accordionContent {


display: block;


width: 100%;


height: 100%;


padding: 0;


position: relative;


}


.accordionContent > table {


text-align: center;


padding: 0;


font-family:"Open Sans", sans-serif;


text-shadow: 0px 1px 0px #fff;


filter: dropshadow(color=#fff, offx=0, offy=1);


}


.accordionContent > table td {


vertical-align: middle;


border-right: 2px groove #eee;


font-size: 12px;


}


.accordionContent > table td {


padding: 10px 5px;


font-weight: 400;


}


.accordionContent .itemOverlay {


position: absolute;


left: 0;


bottom: 0;


width: 100%;


height: 100%;


background: transparent !important;


padding : 0;


-webkit-box-shadow: inset 0px 0px 10px 0px rgba(0, 0, 0, .45);


-khtml-box-shadow: inset 0px 0px 10px 0px rgba(0, 0, 0, .45);


-moz-box-shadow: inset 0px 0px 10px 0px rgba(0, 0, 0, .45);


-o-box-shadow: inset 0px 0px 10px 0px rgba(0, 0, 0, .45);


box-shadow: inset 0px 0px 10px 0px rgba(0, 0, 0, .45);


}


.accordionContent > table td span.unavailable {


font-weight: 200;


}


.accordionContent > table td.last {


border-right: none;


}


.accordionContent > table tr.tableRow_even {


background: #eee;


}


.accordionContent > table tr.tableHeader td {


background: #d2d2d2;


color: #282828;


height: 50px;


font-weight: bold;


font-size: 12px;


padding: 0;


}


.accordionContent > table tr.tableHeader td {


}


.accordionContent > table tr.tableHeader td span {


display: block;


font-size: 10px;


}

最佳答案

我不完全确定您要做什么,但您似乎希望更改表格中各个单元格的高度,我认为这是不可能的。您可以连续更改高度,但不能更改单个单元格。

为此,您可以使用列表、div 甚至其他混合了一些 JS 和 CSS 的 html 容器。

编辑,解决问题的答案:

删除“高度:100%;” from.accordionContent > *

当在 CSS 中使用百分比时,浏览器使用父级的高度而不是元素本身的高度(当然,如果我没记错的话),因此结合 overflow:hidden;这会使最后一排年久失修。

关于HTML/CSS - 高度固定的容器中表格单元格的高度不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14391170/

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