如何更改自定义 css 样式的字体大小? [英] How do you change the font-size of a custom css style?

查看:51
本文介绍了如何更改自定义 css 样式的字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 javascript 更改自定义 css 样式的字体大小?

我已经看到了如何使用 javascript 替换内联样式的示例,但我找不到如何在标题中的非内联自定义样式中替换字体大小等属性.例如,我想使用 javascript 使用 javascript 将字体大小从 12px 更改为 20px.

<风格>.我的风格{字体大小:12px;}</风格>

解决方案

代码如下:

html:

<p class="mystyle">这是一些文字.</p>

javascript:

window.onload=function(){document.getElementsByClassName("mystyle")[0].style.fontSize="120%";}

您还可以将字体大小设置为 smaller , larger ,以 length 为单位,也可以继承父元素的字体大小.>

How do you change the font-size of a custom css style using javascript?

I've seen examples of how to replace inline styles using javascript but I can't find how to replace an attribute like font-size in a non-inline custom style in a header. For example I'd like to use javascript to change the font-size from 12px 20px using javascript.

<head>
<style>
.mystyle{
font-size:12px;
}
</style>

解决方案

Here is the code:

html:

<p class="mystyle">This is some text.</p>

javascript:

window.onload=function(){
document.getElementsByClassName("mystyle")[0].style.fontSize="120%";
}

You can also set the fontsize as smaller , larger, in length units and also inherit font-size of parent element.

这篇关于如何更改自定义 css 样式的字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆