image - 在 CKEditor 5 中设置图像的宽度
问题描述
我有一个页面,我在其中使用 CKEditor 5 和 CKFinder 3。默认情况下,包含在 textarea 中的图像是响应式的,并且只能对齐为full
或right
。
相关页面上有联系人的照片,它们不应该那么大。如何配置通过工具栏按钮插入的图像的宽度?
ClassicEditor
.create( document.querySelector( '#pageTextArea' ), {
image: {
styles: [ { name: 'contact', icon: 'right', title: 'My contact style', className: 'my-contact-side-image' } ]
}
ckfinder: {
uploadUrl: 'example.com/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files&responseType=json'
}
})
.catch( error => {
console.error( error );
process.exit(1);
});
解决方案
要提供一些自定义图像样式,您需要:
首先,配置image.styles选项。
ClassicEditor.create( element, {
// ...
image: {
// ...
styles: [
// Pottentially some other style can go here. E.g. the `full` or `side`.
{ name: 'contact', icon: 'right', title: 'My contact style', className: 'my-contact-side-image' }
]
}
}
其次,通过 CSS 使图像宽度为 100px:
.ck-content figure.image.my-contact-side-image {
float: right;
width: 100px;
}
请注意,您还需要在编辑器之外处理创建内容的样式。
推荐阅读
- generics - 如果我有消息类型列表,如何在 MassTransit 中注册通用消费者适配器
- javascript - 谷歌地图 API JS 上的 3D 地球地球仪
- javascript - Mongoose:.find() 不返回任何文档
- flutter - 如何从单独的文件中使用颤振 url_launcher 函数?
- javascript - 如何在 vscode 中使用正则表达式替换或添加字符串?
- c# - 本地数据库 Visual Studio 2017 的连接问题
- symfony - 如何以 symfony 形式删除默认 ID 和名称?
- java - 双向单机不更新外键
- ruby - 与哈希值一样,哈希键是否有指定的枚举顺序?
- python - 证书验证失败:无法获取本地颁发者证书