使文本高度为 div 的 100%? [英] Make text height 100% of div?
本文介绍了使文本高度为 div 的 100%?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使 div
的文本高度为 100%,但它不起作用.
它只是变成了 body { font-size:?; 的 100%}
.
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
高度是整个页面的 4%,当您调整大小/更改分辨率时,我不想让文本跟随它.
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屋!
查看全文