小编典典

如何检测div元素中的溢出?

html

如何检测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>

阅读 544

收藏
2020-05-10

共1个答案

小编典典

您可以通过将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

2020-05-10