我试图使一个 div
的文本高度达到100%,但不起作用。
它只是变成了 body { font-size:?; }
的100%。
有没有办法使它遵循 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的帮助!
font-size: 4vh
将实现所需的效果。.divWithText {
background-color: white;
border-radius: 10px;
text-align: center;
text-decoration: bold;
color: black;
height: 15vh;
font-size: 15vh;
line-height: 15vh;
}
试一下这个
font
{
position:absolute;
width:100%;
height:100%;
font-family:Verdana, Geneva, sans-serif;
font-size:15px;
font-weight:normal;
}