检查div是否实际上溢出和/或有滚动条 [英] Check if div is actually overflowing and/or has scrollbar

查看:81
本文介绍了检查div是否实际上溢出和/或有滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个页面包含< DIV style =overflow:auto; height:400px;> ... < / DIV> 部分填充来自数据库的信息。有时它包含比可见的更多的文本(因此 overflow:auto ), 。

We have a page with a <DIV style="overflow:auto; height:400px;>...</DIV> section populated with info from a database. Sometimes it contains more text than is visible (hence overflow:auto) and we get a vertical scrollbar.

我们要将< DIV> 部分的底部边框改为红色颜色如果文本溢出 - 因此,当我们没有垂直滚动条(=红色底部边框表示有更多的数据,因为人们不总是看到注意滚动条)。

We would like to change the bottom-border of the <DIV> section to red color IF the text overflows - and as such NOT when we don't have a vertical scrollbar (= the red bottom-border indicates there is more data, because people don't always see pay attention to the scrollbar).

如何实现?

设置 border-bottom:1px solid红色; 将使底部边框红色所有的时间,也当文本的数量不规定溢出/滚动条,因此单独不会剪切它。

Setting "border-bottom:1px solid red;" will make the bottom-border red all the time, also when the amount of text doesn't dictate overflow/scrollbars, so that alone won't cut it.

编辑:你们很快,谢谢!我会看看建议 - 再次感谢!

You guys are fast, thanks! I will look into the suggestions - thanks again!

推荐答案

if (myDiv[0].scrollHeight > myDiv.innerHeight()){
     //this has overflowing contetent!
}
else{
   //remove border, etc.
}

这篇关于检查div是否实际上溢出和/或有滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆