是否可以通过设置尺寸百分比的元素来显示滚动条,而不是增加自身的尺寸?

宇宙

例如,我有尺寸的元件容器width: 100%;height: 100%;overflow: auto;

当我在其中添加更多元素时,这些元素对于容器来说太大了,它增加了自己的面积以适合这些元素,而不是显示滚动条。

有什么解决办法吗?

例子:

<html style = 'height: 100%;'>
    <head>
        <title>test scrolls</title>
    </head>
    <body style = 'height: 100%;'>
        <table border = '1' style = 'width: 100%; height: 100%;'>
            <tr><td id = "test_td" height = '50%' style = 'overflow: scroll;'></td></tr>
            <tr><td height = '50%'><input type = "button" value = "add a lto of junk in first td" onclick = "document.getElementById('test_td').innerHTML = 'asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />'" /></td></tr>
        </table>
    </body>
</html>

好的,div的另一个示例:

<html style = 'height: 100%;'>
    <head>
        <title>test scrolls</title>
    </head>
    <body style = 'height: 100%;'>
        <table border = '1' style = 'width: 100%; height: 100%;'>
            <tr><td height = '50%'><div id = "test_div" style = 'width: 100%; height: 100%; overflow: scroll;'></div></td></tr>
            <tr><td height = '50%'><input type = "button" value = "add a lot of junk in div in first td" onclick = "document.getElementById('test_div').innerHTML = 'asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />asd<br />'" /></td></tr>
        </table>
    </body>
</html>
盖扎萨

这就是你要找的

TD不能滚动,但是您可以在其中滚动一个div。

http://jsfiddle.net/b9kzbf8c/1/

div.scrollable {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: auto;
}

<table border = '1' style = 'width: 100%; height: 100%;'>
    <tr style="height: 40px; overflow-y: scroll;">
        <td>
            <div class=scrollable>Some content with a scrollbar if it's too big for the cell
                Some content with a scrollbar if it's too big for the cell
                Some content with a scrollbar if it's too big for the cell
            </div>
        </td>
    <table>

编辑

我也用jQuery完成了

http://jsfiddle.net/pwcd9cxe/2/

<script type="text/javascript">
    var equalHeights;

    resize = function(me){
        equalHeights = me;
        $('.td').height(($(equalHeights).height())/2);
    };

    $(window).resize(function(){
        $('.td').height(($(equalHeights).height())/2);
    });

    resize($(window));
</script>

<style>
    .td {overflow-y: scroll;}
</style>

<div class="td">
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
</div>
</div>
<div class="tr">
<div class="td">
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
    Some content here that is copy pasted to fill up space. <br />
</div>

编辑

我已经做到了没有任何JS。

http://jsfiddle.net/pwcd9cxe/3/

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在引导程序中以百分比形式设置div的高度而没有滚动条

来自分类Dev

尽管分配了百分比宽度,但 IMG 仍会生成滚动条

来自分类Dev

将视图高度设置为屏幕尺寸的百分比(以编程方式)

来自分类Dev

装箱尺寸:边框;百分比宽度,但像素填充

来自分类Dev

尺寸相同但重量不同时的百分比计算

来自分类Dev

循环进度条滚动显示-百分比文本问题

来自分类Dev

我可以将电源指示器设置为显示电池百分比而不是剩余时间吗?

来自分类Dev

当孩子的高度未知时,父母的孩子的滚动条具有最大高度的百分比

来自分类Dev

我可以通过改造下载时增加一个百分比吗?

来自分类Dev

我们可以显示Grapgh Tableau线的百分比增加吗?

来自分类Dev

用百分比显示进度条

来自分类Dev

显示进度条的非百分比值

来自分类Dev

是否可以在不拉伸或不显示滚动条的情况下使我的幻灯片中的所有图像全尺寸

来自分类Dev

如何使用百分比而不是像素将背景图像设置为伪元素?

来自分类Dev

使表格显示百分比而不是R中的频率

来自分类Dev

如何显示百分比而不是barplot中的值?

来自分类Dev

如何显示百分比而不是barplot中的值?

来自分类Dev

在Tableau中,是否可以仅在总计列中显示百分比?

来自分类Dev

CSS设置元素的高度百分比

来自分类Dev

通过 HTML 设置渐变百分比值

来自分类Dev

如何在不同屏幕尺寸下使用字体百分比

来自分类Dev

元视口和宽度=设备宽度与尺寸百分比

来自分类Dev

使用PCA减少尺寸,同时保留百分比差异

来自分类Dev

如何使用百分比(高度,宽度)尺寸的CSS位置(相对,绝对)?

来自分类Dev

3个Divs,具有按比例缩放的不同屏幕尺寸百分比

来自分类Dev

并排Div,以一个固定的尺寸和另一宽度作为百分比

来自分类Dev

如何在不同屏幕尺寸下使用字体百分比

来自分类Dev

放大时,图像尺寸在屏幕上的百分比保持不变

来自分类Dev

找到值的增加百分比

Related 相关文章

  1. 1

    如何在引导程序中以百分比形式设置div的高度而没有滚动条

  2. 2

    尽管分配了百分比宽度,但 IMG 仍会生成滚动条

  3. 3

    将视图高度设置为屏幕尺寸的百分比(以编程方式)

  4. 4

    装箱尺寸:边框;百分比宽度,但像素填充

  5. 5

    尺寸相同但重量不同时的百分比计算

  6. 6

    循环进度条滚动显示-百分比文本问题

  7. 7

    我可以将电源指示器设置为显示电池百分比而不是剩余时间吗?

  8. 8

    当孩子的高度未知时,父母的孩子的滚动条具有最大高度的百分比

  9. 9

    我可以通过改造下载时增加一个百分比吗?

  10. 10

    我们可以显示Grapgh Tableau线的百分比增加吗?

  11. 11

    用百分比显示进度条

  12. 12

    显示进度条的非百分比值

  13. 13

    是否可以在不拉伸或不显示滚动条的情况下使我的幻灯片中的所有图像全尺寸

  14. 14

    如何使用百分比而不是像素将背景图像设置为伪元素?

  15. 15

    使表格显示百分比而不是R中的频率

  16. 16

    如何显示百分比而不是barplot中的值?

  17. 17

    如何显示百分比而不是barplot中的值?

  18. 18

    在Tableau中,是否可以仅在总计列中显示百分比?

  19. 19

    CSS设置元素的高度百分比

  20. 20

    通过 HTML 设置渐变百分比值

  21. 21

    如何在不同屏幕尺寸下使用字体百分比

  22. 22

    元视口和宽度=设备宽度与尺寸百分比

  23. 23

    使用PCA减少尺寸,同时保留百分比差异

  24. 24

    如何使用百分比(高度,宽度)尺寸的CSS位置(相对,绝对)?

  25. 25

    3个Divs,具有按比例缩放的不同屏幕尺寸百分比

  26. 26

    并排Div,以一个固定的尺寸和另一宽度作为百分比

  27. 27

    如何在不同屏幕尺寸下使用字体百分比

  28. 28

    放大时,图像尺寸在屏幕上的百分比保持不变

  29. 29

    找到值的增加百分比

热门标签

归档