javascript 如何在summernote中设置字体大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27011485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set font-size in summernote?
提问by Bazinga777
I have been using summernote as my default text editor but I haven't been able to set a particular font-size by default when i initialize it.
我一直使用summernote作为我的默认文本编辑器,但在初始化时我无法默认设置特定的字体大小。
so far I have tried
到目前为止我已经尝试过
$('.active-textcontainer').summernote({
toolbar: [
['style', ['bold', 'italic', 'underline']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']]
],
height:150,
fontsize:'18px'
});
and
和
$('.active-textcontainer').summernote({
toolbar: [
['style', ['bold', 'italic', 'underline']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']]
],
height:150,
fontsize:'18'
});
Ant help will be appreciated.
蚂蚁的帮助将不胜感激。
回答by albciff
I've never use summernote
, however looking at the APIthere is nothing (at least now) to specify default font size, I make a test doing some tries like you and seems that no one works.
我从来没有使用过summernote
,但是查看API没有任何东西(至少现在)来指定默认字体大小,我做了一个像你一样尝试的测试,但似乎没有人工作。
A possible solution to this is to apply directly the font-size
style to the editor div
using jQuery
because when you initialize summernote
in an object always create the follow div
: <div class="note-editable" ...>...</div>
. So you can do the follow after initialization $('.note-editable').css('font-size','18px');
in your code this could be:
一个可能的解决方案是直接将font-size
样式应用到编辑器div
usingjQuery
因为summernote
在对象中初始化时总是创建以下内容div
:<div class="note-editable" ...>...</div>
。因此,您可以$('.note-editable').css('font-size','18px');
在代码中初始化后执行以下操作,这可能是:
$('.active-textcontainer').summernote({
toolbar: [
['style', ['bold', 'italic', 'underline']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']]
],
height:150
});
$('.note-editable').css('font-size','18px');
This solution it's a little tricky an if the class
name of the div
editor change on the next version this will not work however maybe it's enough for your case.
这个解决方案有点棘手,如果编辑器的class
名称div
在下一个版本中更改,这将不起作用,但也许它对您的情况已经足够了。
Hope this helps,
希望这可以帮助,
回答by PowPi
or set the default via css
或通过 css 设置默认值
.note-editor .note-editable {
line-height: 1.2;
font-size: 18px;
}
回答by Dan Dascalescu
You can set the font size of the currently selected text,
您可以设置当前选中文本的字体大小,
$('.summernote').summernote('fontSize', 40);
but there seems to be no API to select text.
但似乎没有选择文本的 API。
Being unable to set the default font size is quite strange, so I filed an issue in their repo.
无法设置默认字体大小很奇怪,所以我在他们的 repo 中提交了一个问题。