gpt4 book ai didi

html - 滚动包含图像的 DIV,而不是文档

转载 作者:太空宇宙 更新时间:2023-11-04 13:35:26 24 4
gpt4 key购买 nike

我在一个 div 中有一个大图像,我想滚动它。但是我没有滚动 div,而是滚动文档。

如何让图像在 DIV 中滚动而不是在父级或文档中滚动?

我的代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Force Scroll</title>
<style type="text/css">
.scrollable
{
overflow: auto;
}
</style>
</head>
<body>

<div class="scrollable">
<img src="image.jpg" alt="test image" />
</div>

</body>
</html>

最佳答案

为 div 设置一个(最大)宽度和高度,它应该可以工作。否则 div 将自行调整以适应图像的大小:

#mydiv {
overflow: auto;

max-width: 800px; // or width instead of max-width
max-height: 600px; // or height instead of max-height
}

此处示例:http://jsfiddle.net/x58RD/ .


如果碰巧你被迫支持IE6这样的老式浏览器,你需要使用widthheight而不是max-widthmax-height 无论如何,否则它仍然无法工作。

关于html - 滚动包含图像的 DIV,而不是文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6521798/

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