[英]CSS: Dynamically resizing font in container that is 100vh
Problem: I have a container that is 100vh, when the screen shrinks, I would like the font to shrink with it and always fit within the container, never spilling over it. 问题:我有一个100vh的容器,当屏幕缩小时,我希望字体随其收缩,并始终适合该容器,永远不要溢出。
Notes: I know this can be done pretty simply with @media css rules, but I'm wondering whether or not is it possible to accomplish without @media or dynamically 注意:我知道可以使用@media css规则很简单地完成此操作,但是我想知道是否可以在没有@media的情况下或动态地完成
Fiddle: https://jsfiddle.net/wm0n4mys/ 小提琴: https : //jsfiddle.net/wm0n4mys/
.container{ border:1px solid black; text-align:center; height:100vh; } h2{ font-size:60px; } *{ box-sizing:border-box; padding:0; margin:0; }
<div class="container"> <h2 class="main">A TITLE THATS TALKING ABOUT SOMETHING BIG AND THIS IS A PRETTY BIG TITLE MAN I GET IT YO</h2> <p class="text">Something, Something, Something, Something, Something, Something Something Something Something Something SomethingSomething SomethingSomethingSomethingSomethingSomethingSomething</p> </div>
Use vw
, or vh
, as font size unit 使用
vw
或vh
作为字体大小单位
.container{ border:1px solid black; text-align:center; height:100vh; } h2{ font-size:5vw; } *{ box-sizing:border-box; padding:0; margin:0; }
<div class="container"> <h2 class="main">A TITLE THATS TALKING ABOUT SOMETHING BIG AND THIS IS A PRETTY BIG TITLE MAN I GET IT YO</h2> <p class="text">Something, Something, Something, Something, Something, Something Something Something Something Something SomethingSomething SomethingSomethingSomethingSomethingSomethingSomething</p> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.