我有一个宽度为70%的div,这就是我想要做的事情:
这只能用css吗?这是我的代码:
.parent {
width:70%;
height:auto;
min-height:100px;
background:red;
font-size:10vw;
}

Please help me to change the font-size dynamically to the parent class
<hr>
<div class="parent">
This Text
</div>
&#13;
注意:div 大小响应,这很重要。 提前谢谢!
答案 0 :(得分:4)
也许不是你正在寻找的东西,但有些东西 - 你可以使字体和元素相对于视图宽度。
p {
font-size: 5vw;
background-color: red;
width: 50vw;
}
&#13;
<p>
I'm a P!
</p>
&#13;
答案 1 :(得分:1)
您只需在代码中添加display: inline;
.parent {
width:70%;
height:auto;
min-height:100px;
background:red;
font-size:10vw;
display: inline;
}
&#13;
<!DOCTYPE html>
<html>
<head>
<style>
.parent {
width:70%;
height:auto;
min-height:100px;
background:red;
font-size:10vw;
display: inline;
}
</style>
</head>
<body>
<div class="parent">
This Text
</div>
</body>
</html>
&#13;
答案 2 :(得分:0)
**You can change font-size:10vh;**
.parent {
width:70%;
height:auto;
min-height:100px;
background:red;
color:white;
font-size:10vh;
}
Please help me to change the font-size dynamically to the parent class
<hr>
<div class="parent">
Text
</div>
答案 3 :(得分:-2)
是的,但我认为你需要使用JS(jQuery)。
JS:
$(function(){
var box = $('.box');
var boxWith = box.width();
$('.box h1').css('font-size',boxWith);
});
答案 4 :(得分:-2)
在这里,我更新了它.... JS Fiddel
尝试使用
CSS
.parent
{
width:70%;
height:auto;
min-height:100px;
background:red;
font-size:10vw;
}
span{
display:inline-block;
transform:scale(1.8,1);
-webkit-transform:scale(3,1);
}
HTML
<div class="parent">
<span>This Text</span>
</div>