最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Tinymce how to float an image? - Stack Overflow

programmeradmin1浏览0评论

By default in tinymce there are no image floating, only image, text alignment should I do it manually or there already are some plugins? can't find any...or how can I get the current selected elements and float them?

By default in tinymce there are no image floating, only image, text alignment should I do it manually or there already are some plugins? can't find any...or how can I get the current selected elements and float them?

Share Improve this question asked May 19, 2014 at 3:44 RustamRustam 2494 silver badges11 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 13

you can use style_formats option.
Document is here: https://www.tiny.cloud/docs/configure/content-formatting/#style_formats

This option enables you to add more advanced style formats for text and other elements to the editor. The value of this option will be rendered as styles in the Formats dropdown.

You can go like this when you initialize a tinymce.

tinymce.init({
    ...
    style_formats: [
    {
        title: 'Image Left',
        selector: 'img',
        styles: {
            'float': 'left', 
            'margin': '0 10px 0 10px'
        }
     },
     {
         title: 'Image Right',
         selector: 'img', 
         styles: {
             'float': 'right', 
             'margin': '0 0 10px 10px'
         }
     }
]
});

Hope this helps.

In TinyMce v4 and v5, when you have the image plugin in place,

plugins: [
    "... image"
],

then you can use the image_class_list property to allow the user to add classes to the images.

For instance, in the example below, the user makes the image float right, selecting the 'Right' option. I have assigned to that option some TailwindCSS classes. The one that makes the image float is float-right.

image_class_list: [
    { title: 'Left', value: '' },
    { title: 'Right', value: 'w-full md:float-right' }
],

Here the official documentation of image_class_list: https://www.tiny.cloud/docs/plugins/opensource/image/#image_class_list

If you want also to make the image float in the editor you also have to add the content_style property and assign the corresponding CSS attributes.

content_style: "body img.md\\:float-right{ float: right; }"
               

Here the official documentation of content_style: https://www.tiny.cloud/docs/configure/content-appearance/#content_style

发布评论

评论列表(0)

  1. 暂无评论