将文字高度设为div的100%? [英] Make text height 100% of div?

查看:132
本文介绍了将文字高度设为div的100%?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使文本100%高度的 div ,但它不工作。
它只是 body {font-size:?; }

I'm trying to make the text 100% height of a div but it doesn't work.
It just becomes 100% of the body { font-size:?; }.

有没有办法让它跟随div高度?

div height

Is there any way to make it follow the div height?
The div height is 4% of the whole page and I wan't the text to follow it when you resize/change resolution.

推荐答案

要调整大小/更改分辨率时,得到我想要的结果,我不得不使用这个代码:

To get the result I wanted, I had to use this code:

// Cache the div so that the browser doesn't have to find it every time the window is resized.
var $div = $('li.leaf.item');

// Run the following when the window is resized, and also trigger it once to begin with.
$(window).resize(function () {
// Get the current height of the div and save it as a variable.
var height = $div.height();
// Set the font-size and line-height of the text within the div according to the current height.
$div.css({
'font-size': (height/2) + 'px',
'line-height': height + 'px'
})
}).trigger('resize');​

谢谢joshuanhibbert @ css-tricks的帮助!

Thank you joshuanhibbert@css-tricks for the help!

这篇关于将文字高度设为div的100%?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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