我想知道是否可以使用flexbox项目的高度来设置字体大小。我的flexbox容器使用视口单位进行设置,项目的高度是通过flex-grow属性确定的。我想要做的是将字体大小设置为这些项目的高度,并在视口改变时保留这些关系。
我有一个基本的想法,有些效果,但我不确定如何仅隔离字母(基线到大写字母高度)并将其缩放到项目容器中。
欢迎提出任何建议,或者遇到任何问题,请参考以下HTML链接:https://codepen.io/NewbCake/pen/JvwNJq(垂直调整窗口大小以设置字体大小)。
我有一个基本的想法,有些效果,但我不确定如何仅隔离字母(基线到大写字母高度)并将其缩放到项目容器中。
欢迎提出任何建议,或者遇到任何问题,请参考以下HTML链接:https://codepen.io/NewbCake/pen/JvwNJq(垂直调整窗口大小以设置字体大小)。
<section class="center">
<div class="container">
<div class="item1">H</div>
<div class="item2">H</div>
</div>
</section>
CSS
section {
display:flex;
flex-direction:row;
height:95vh;
width:100%;
border:1px solid red;
}
.container {
display:flex;
flex-direction:column;
height:80vh;
width:80vh;
border:1px solid blue;
}
.container_wide {
display:flex;
flex-direction:column;
height:80vh;
width:80vh;
border:1px solid blue;
}
.center {
justify-content:center;
align-items:center;
}
.item1 {
flex-grow:1;
flex-shrink:0;
flex-basis:auto;
border:1px solid green;
line-height:.75;
}
.item2 {
flex-grow:3;
flex-shrink:0;
flex-basis:auto;
border:1px solid green;
line-height:.75;
}
JS
var resizeTimer;
$(window).on('resize', function(e) {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
// Run code here, resizing has "stopped"
$(".item1").css("font-size", $(".item1").css("height"));
$(".item2").css("font-size", $(".item2").css("height"));
}, 250);
});
非常感谢您的帮助!