我有一个div,我给了它一些特定的line-height
和width
。
我在下面放置了代码
document.getElementById("content").onload = countLines();
function countLines() {
var el = document.getElementById('content');
var divHeight = el.offsetHeight
var lineHeight = parseInt(el.style.lineHeight);
var lines = divHeight / lineHeight;
console.log("Lines: " + lines);
}
<div id="content" style="width: 80px; line-height: 20px">
hello how are you? hello how are you? hello how are you? hello how are you?
</div>
但是我只想显示该div
中的3行,并删除该div
中的所有其他生命,而这3个数字是动态变化的,我想用jquery删除所有其他行。
有人可以帮我吗?>
我有一个div,我给了它一些特定的行高和宽度。我将代码放在document.getElementById(“ content”)。onload = countLines();下。函数countLines(){var el = ...
您可以为元素设置overflow
和max-height
css属性,如下所示: