gpt4 book ai didi

html - 是否可以制作具有 % 设置尺寸的元素来显示卷轴,而不是增加自己的尺寸?

转载 作者:行者123 更新时间:2023-11-27 23:51:12 25 4
gpt4 key购买 nike

例如,我有一个元素容器,其尺寸为 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/

关于html - 是否可以制作具有 % 设置尺寸的元素来显示卷轴,而不是增加自己的尺寸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27149133/

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