在我的应用程序中有字段更改字体实际上使用该用户可以更改整个应用程序的字体。如果我的项目中有100个字段(可能是不同的字体大小,这实际上是可能的)用户如何改变字体大小。它可以反映整个应用程序。当我瞪眼时,我发现有放大和缩小的功能。这不是一个好方法。有没有办法改变整个应用程序的字体?
答案 0 :(得分:2)
本文展示了一种在CSS中执行此操作的好方法。
http://joshnh.com/2011/07/26/are-you-using-ems-with-your-media-queries/
关键是仅使用em
,然后您可以通过更改em
的基数来全局切换字体大小。
答案 1 :(得分:2)
您可以动态创建样式并将其应用于body
中的所有元素。
<强> Demo 强>
$('#select_font').on('change', function () {
var style;
var font = $(this).val();
if ($('head').find('style.font').length === 0) {
style = $('<style class="font">.font { font-size: ' + font + ' !important; }</style>');
$('head').append(style);
$('body *').addClass('font');
} else {
$('body *').removeClass('font');
$('style.font').empty();
style = '.font { font-size: ' + font + ' !important; }';
$('style.font').append(style);
$('body *').addClass('font');
}
});