gpt4 book ai didi

css - 使文本高度为 div 的 100%?

转载 作者:技术小花猫 更新时间:2023-10-29 10:37:22 26 4
gpt4 key购买 nike

我试图将文本设置为 div 的 100% 高度,但它不起作用。
它刚好变成正文的100% { font-size:?; }

有什么办法可以让它跟随div的高度吗?
div 高度是整个页面的 4%,当您调整大小时/更改分辨率时,我不希望文本跟随它。

最佳答案

为了得到我想要的结果,我不得不使用这段代码:

// 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 的帮助!

关于css - 使文本高度为 div 的 100%?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10718840/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com