通过字体大小和行数设置 div 高度
我想要一个函数通过计算行数自动设置 div 高度。我试图成功但它停止了。请帮助我。
function set_height() {
var div_obj=document.getElementById('dogodkiinhalt'); //get object by id -> <div>
var number_of_lines=div_obj.style.offsetHeight; //get number of lines in this obj.
var font_size=??; //get font size and i don't know how
var div_Height=number_of_lines*font_size; //calculating new height
document.getElementById('dogodkiinhalt').style.height = div_Height; //setting new height to div
}
我正在寻找如何获取文本大小,但我什么也没找到。 会这样吗?
i want o make a function to set div height automaticly by counting lines. I tried to make it seccessfully but it stops. Please help mi with that.
function set_height() {
var div_obj=document.getElementById('dogodkiinhalt'); //get object by id -> <div>
var number_of_lines=div_obj.style.offsetHeight; //get number of lines in this obj.
var font_size=??; //get font size and i don't know how
var div_Height=number_of_lines*font_size; //calculating new height
document.getElementById('dogodkiinhalt').style.height = div_Height; //setting new height to div
}
i was looking up how to get text size, but i found nothing.
wolud be that kind of tkinking ok?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需将 div 的高度保留为 auto 即可。
just leave the height of the div as auto.