简体   繁体   English

表列溢出-y:滚动,同时让溢出-x自动/可见

[英]Table-column overflow-y: scroll while letting overflow-x be auto/visible

I have a table with two columns. 我有一张两列的桌子。 I want the first column to be scrollable, so that my table can stay at a fixed height and not expand continuously. 我希望第一列是可滚动的,以便我的桌子可以保持固定的高度,并且不能连续扩展。 I only want it to be scrollable vertically though: Horizontally the overflowing parts should still be visible (In my case, the overflowing parts are on-hover tooltips which are getting hidden and add a horizontal scrollbar...), without having to scroll horizontally. 我只希望它在垂直方向上可滚动:水平方向上的溢出部分仍然可见(在我的情况下,溢出部分是悬停的工具提示,这些提示被隐藏并添加了水平滚动条...),而不必水平滚动。 My CSS/HTML looks like this: 我的CSS / HTML如下所示:

<table class"tab1">
    <td class="td1"><div class="container"><!-- Many, many, many floating elements here --></div></td>
    <td></td>
</table>

CSS: CSS:

.tab1 {
    table-layout: fixed;
    width: 100% /*100% of the parent node*/
    height: 20em;
}
.td1.container {
    overflow-y: scroll;
}

2 Problems: 2个问题:

  • The height of 20em gets ignored. 20em的高度被忽略。 Even though the first column now gets a scrollbar, it still expands to its own needs. 即使第一列现在有了滚动条,它仍然可以扩展到自己的需要。
  • When hovering over one of my elements, which generates a div with position:absolute , a horizontal scrollbar appears and the part of the tooltip that overflows gets hidden. 将鼠标悬停在我的一个元素上时,该元素会生成一个带有position:absolute的div,出现水平滚动条,并且溢出的工具提示部分将被隐藏。

How can I fix this? 我怎样才能解决这个问题?

PS: The code is simplified of course, but I hope that it still illustrates my problem well. PS:当然可以简化代码,但是我希望它仍然可以很好地说明我的问题。

PPS: Here is a JSFiddle: jsfiddle.net/pg0cLpjd PPS:这是一个JSFiddle:jsfiddle.net/pg0cLpjd

This question is even more difficult than I thought... 这个问题比我想象的还要困难。
But here is a partial solution: 但这是部分解决方案:

  • table-layout: fixed; only applies to the table itself and its columns; 仅适用于表本身及其列; not the height. 不是高度。 A table will always grow with its content. 表格将始终随其内容一起增长。 But there are a couple workarounds: 但是有两种解决方法:

    1. Set your table to display: block; 将表设置为display: block; , give it a specified height and set its overflow-y: scroll; ,为其指定一个指定高度并设置其overflow-y: scroll; (This also might solve your second problem, depending on your needs) (这也可能会解决您的第二个问题,具体取决于您的需求)
    2. Place a div with a specified height around your table and set overflow-y: scroll; 在桌子周围放置一个具有指定高度的div并设置overflow-y: scroll; . The table still grows inside the div but you have a scrollbar. 该表仍在div内增长,但是您具有滚动条。
    3. Place a div in your columns with a specified height and set overflow-y: scroll; 在您的列中以指定的高度放置div并设置overflow-y: scroll; . This differs from the first attempt only in the position of the scrollbars and you can scroll every cell independently. 这与第一次尝试的区别仅在于滚动条的位置,您可以独立滚动每个单元格。 But this has one huge disadvantage, which I am going to explain now: 但这有一个巨大的缺点,我现在要解释一下:
  • As this answer says: If you set one overflow direction to something else than visible , the other overflow direction will automatically set to auto . 如此答案所言:如果将一个溢出方向设置为除visible的其他方向,则另一个溢出方向将自动设置为auto ( it's a feature, not a bug ). 这是一个功能,而不是错误 )。 And this is exactly where the second problem lies. 这正是第二个问题所在。 Your code has the right logic, but it's just not possible. 您的代码具有正确的逻辑,但这是不可能的。 There are solutions using a wrapper div, (it didn't work for me) but you could give it a try. 有一些使用包装器div的解决方案(它对我不起作用),但是您可以尝试一下。
    I'd recommend having a look on how to make tooltips with JavaScript. 我建议您看看如何使用JavaScript制作工具提示。 There are plenty tutorials out there on the internet. 互联网上有很多教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM