css - Webkit 从设置高度到文本高度的过渡

标签 css html webkit css-transitions

我正在尝试使具有已定义 高度的 div 过渡到由其文本内容确定的新高度。据推测,这需要考虑窗口的宽度,因为随着窗口宽度的减小,文本会换行更多,变得更长,并且需要更大的高度值。

#object {
    width: 100%;
    height: 50px;
    -webkit-transition: height 0.5s;
}
#object:hover {
    height: <!-- new height depends on length of inner text, but also
                 how small the window size is, because of wrapping -->
}

有没有一种有效的方法来实现这一点?

最佳答案

将高度设置为自动。 div 的高度将根据 div 内的内容进行调整。

关于css - Webkit 从设置高度到文本高度的过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19308942/

相关文章:

html - 如何使用 CSS 在 IE 8 中创建圆 Angular ?

CSS 两个 div 宽度 50% 在一行中,文件中有换行符

html - margin-right 没有显示

javascript - 我如何从 CasperJS 访问 iframe?

python - 如何使用 HTML + Javascript 构建 python GUI?

html - Bootstrap 网格系统在 Rails 中格式化照片

html - 如何从我的网站中删除额外的宽度?

html - 如何在这样的按钮中添加阴影?

javascript - 如何计算 HTML Canvas 弧线结束 Angular 的 x 和 y 坐标?

css - 我可以将 Firefox 和 Webkit 样式选择器分组吗?如果不是,为什么?