如果容器宽度,填充和线高已知,如何计算高度? [英] If container width, padding and line-height is known, how to calculate height?

查看:59
本文介绍了如果容器宽度,填充和线高已知,如何计算高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向DOM动态添加元素。

I am adding element dynamically to DOM.

$('<div class="entry"></div>').text(data.status).appendTo(app.twitter_feed);

我希望在将元素高度添加到DOM之前获取元素高度。通常的方法是在隐藏元素中添加具有相同样式的元素,然后只需查看高度是多少。

I want to get element height before it is added to DOM. The usual approach is to add the element within a hidden element with the same style and then simply see what is the height.

但是,如果计算元素高度是不可能的你知道容器的宽度,填充和行高(内容只是纯文本)和内容吗?

Though, is it imposible to calculate element height if you know container's width, padding and line-height (content is only plain-text) and content?

推荐答案

内容如何包装容器内部可能依赖于浏览器和缩放级别,所以除非你非常确定内容永远不会包装,否则我建议你按照你所描述的方式确定高度。

How the content wraps inside a container may depend on browser and zoom level, so unless you're very sure the content will never wrap, I would advise determining the height the way you have described.

这篇关于如果容器宽度,填充和线高已知,如何计算高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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