ckeditor 中的自定义字体
我正在尝试添加自定义字体但不能。我在下面的代码中遇到错误,字体名称正在添加到下拉列表中,但它没有改变...
我的代码是
config.js:
CKEDITOR.editorConfig = function( config )
{
config.contentsCss = 'fonts.css';
config.font_names = 'Dekers/dekers_true' + config.font_names;
}
fonts.css:
@font-face {
font-family: "dekers_true", serif;
src: url(fonts/Dekers_light.eot ); /* IE */
src: local("Dekers"), url("fonts/Dekers_light.ttf") format("truetype"); /*non-IE*/
}
I am trying to add a custom font but can't. I am getting error with below code, The font name is adding in the drop down but it's not changing...
my code is
config.js:
CKEDITOR.editorConfig = function( config )
{
config.contentsCss = 'fonts.css';
config.font_names = 'Dekers/dekers_true' + config.font_names;
}
fonts.css:
@font-face {
font-family: "dekers_true", serif;
src: url(fonts/Dekers_light.eot ); /* IE */
src: local("Dekers"), url("fonts/Dekers_light.ttf") format("truetype"); /*non-IE*/
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用托管字体并且用例相对简单,则可以将样式表直接添加到
config.contentCss
:config.contentsCss = [ '/css/mysitestyles.css' , 'https://fonts.googleapis.com/css?family=Roboto' ]
第一个文件定义您的样式(例如
.title { font-family: 'Roboto', sans-serif;
),第二个是包含字体定义的远程样式表。自定义字体现在应该出现在下拉菜单和编辑器中,前提是您已在 config.styleSet 中定义了可选样式:
config.styleSet = [ { 'name': 'Title' , 'element': 'h1', 'attributes': { 'class': 'title' } ]
我使用 CKEditor Django 插件对此进行了测试,其中语法与上面的略有不同,但是我看不出有什么理由不能翻译。
If you're using hosted fonts and have a relatively simple use case, you can just add the stylesheets directly to
config.contentCss
:config.contentsCss = [ '/css/mysitestyles.css', 'https://fonts.googleapis.com/css?family=Roboto' ]
Where the first file defines your styles (e.g.
.title { font-family: 'Roboto', sans-serif;
) and the second one is the remote stylesheet containing the font definitions.The custom fonts should now appear in the drop-down menu and editor, providing you have defined the selectable styles in
config.styleSet
:config.styleSet = [ { 'name': 'Title', 'element': 'h1', 'attributes': { 'class': 'title' } ]
I tested this using the CKEditor Django plugin, where the syntax is a little different to the above, but I can't see any reason why it wouldn't translate.
您的自定义 CSS 文件必须包含 CKEditor 主体的基本样式。 CKEditor 仅使用此 CSS 文件加载 iframe。
然后将字体声明添加到主站点的 CSS 文件中。
更新:替代变体。
您可以声明您的自定义样式,例如,
因此将应用类
.pretty_face
,并且您可以根据需要对其进行样式设置。如果你想在 rte 中立即预览,你还需要在 contentCSS 文件中设置此类的样式。Your custom CSS file must contain the basic styling for CKEditor body. CKEditor loads in the iframe with this CSS file only.
And than add font declaration into your main site's CSS file too.
Upd: Alternative variant.
You can declare your custom styles, e.g.
So will be applied class
.pretty_face
and than you can style it as you wish. If you want immediate preview in rte, you need to style this class in contentsCSS file too.或者在 config.js 中
,然后是你的 CSS。
上面将其放置在“样式”下拉列表中,而不是“字体”中。
OR in config.js
And then your CSS.
The above places it in Styles dropdown, not Fonts.