我想允许用户更改整个网页的font-size
。
我已经在 rem 中设置了字体大小,我正在尝试更改根的字体大小,以便它反射(reflect)所有元素。
我的标记-
<body >
<div id="test-text">
ALL TEXT
</div>
<p>sample text</p>
<p>sample text2</p>
<span>sample text3</span>
<h1>tst4</h1>
<label>label</label>
<button id="inc">inc</button>
</body>
代码-
$('#inc').click(function(){
$('body').css('font-size','4rem !important');
})
CSS-
p{
font-size: 2rem;
}
span{
font-size: 0.5rem;
}
代码没有反射(reflect)任何东西。我在这里缺少什么?
最佳答案
jQuery 并不总是能识别 !important
。删除 !important
它应该可以工作。
How to apply !important using .css()?
$('#inc').click(function(){
$('body').css('font-size','4rem');
})
p{
font-size: 2rem;
}
span{
font-size: 0.5rem;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="test-text">
ALL TEXT
</div>
<p>sample text</p>
<p>sample text2</p>
<span>sample text3</span>
<h1>tst4</h1>
<label>label</label>
<button id="inc">inc</button>
关于javascript - 更改正文中所有文本元素的字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64339857/