gpt4 book ai didi

javascript - 如何检测div元素溢出?

转载 作者:IT王子 更新时间:2023-10-29 03:09:29 27 4
gpt4 key购买 nike

如何检测 div 元素中的垂直文本溢出?

CSS:

div.rounded {
background-color:#FFF;
height: 123px;
width:200px;
font-size:11px;
overflow:hidden;
}

HTML:

<div id="tempDiv" class="rounded">
Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Phasellus vel quam vestibulum orci blandit laoreet.
</div>

最佳答案

您可以通过比较 scrollHeight 和 clientHeight 轻松做到这一点,尝试以下操作:

<script type="text/javascript">
function GetContainerSize ()
{
var container = document.getElementById ("tempDiv");
var message = "The width of the contents with padding: " + container.scrollWidth + "px.\n";
message += "The height of the contents with padding: " + container.scrollHeight + "px.\n";

alert (message);
}
</script>

更多信息请查看:http://help.dottoro.com/ljbixkkn.php

关于javascript - 如何检测div元素溢出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7138772/

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