[英]How can I make a dynamic font-size base on parent element's size?
Here is my code: 这是我的代码:
ul { list-style-type: none; white-space:nowrap; } li { padding: 5px; border: 1px solid; display:inline-block; width:50px; height: 20px; text-align: center; }
<ul> <li>one</li> <li>two</li> <li>three</li> </ul>
I didn't set font-size
property to it. 我没有设置font-size
属性。 Now I want to know, can I set a dynamic font-size
to it? 现在我想知道,我可以为其设置动态font-size
吗? I mean, I want a bigger font-size
for this one: 我的意思是,我想要一个更大的font-size
:
ul { list-style-type: none; white-space:nowrap; } li { padding: 5px; border: 1px solid; display:inline-block; width:90px; height: 25px; text-align: center; }
<ul> <li>one</li> <li>two</li> <li>three</li> </ul>
Because of bigger both width
and height
for <li>
in second code snippet. 由于第二个代码段中<li>
width
和height
都较大。 Is doing that possible? 有可能吗?
What about using vw
? 使用vw
呢? See fiddle and resize the window https://jsfiddle.net/d456eLwt/ 查看小提琴并调整窗口大小https://jsfiddle.net/d456eLwt/
ul { list-style-type: none; white-space:nowrap; } li { padding: 5px; border: 1px solid; display:inline-block; width: 20vw; font-size: 5vw; line-height: 5vw; height: 5vw; text-align: center; }
<ul> <li>one</li> <li>two</li> <li>three</li> </ul>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.