Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Steve Fabian 21 posts 102 karma points
    Jan 16, 2017 @ 15:49
    Steve Fabian
    0

    Add padding to rich text editor?

    Is it possible to add a button to the rich text editor that would allow users to add padding to an image? I guess one option would be to set up a style sheet for it but I was wondering if there may be a better/earier way. Thanks!

  • David Peck 687 posts 1863 karma points c-trib
    Jan 16, 2017 @ 17:38
    David Peck
    100

    I doubt it. You might do better to use the grid editor. Then you can either have a 'Padded image' grid editor item or you can add a CSS class to the row that contains the image.

    You could also apply a CSS class the image by adding an style to the stylesheet, but your editor might find this unintuitive. http://umbraco.tv/videos/umbraco-v7/implementor/fundamentals/stylesheets-and-javascript/setting-up-rte-styles/documentation

  • Matthew Kirschner 323 posts 611 karma points
    Jan 17, 2017 @ 18:47
    Matthew Kirschner
    0

    My issue with using the grid editor for floating images beside content is that the text doesn't wrap, leading to unwanted white space.

  • Steve Fabian 21 posts 102 karma points
    Jan 16, 2017 @ 20:37
    Steve Fabian
    0

    David, Thanks for the info. I'll check that out. Steve

  • Matthew Kirschner 323 posts 611 karma points
    Jan 17, 2017 @ 18:45
    Matthew Kirschner
    0

    I have yet to find a great solution to this that also gives editors control over how much padding to give an image. Instead, I've opted for an absolute approach that adds margin to all images with a left or right alignment. This is done in two stages, one targeting the RTE itself in the backoffice and the other targets the content rendered on the front-end.

    Here's my stylesheet for the backoffice RTE:

    body.mce-content-body img {
        margin-bottom: 1.777em;
    }
    
    body.mce-content-body img[style*="right"] {
        margin-left: 1.5em;
    }
    
    body.mce-content-body img[style*="left"] {
        margin-right: 1.5em;
    }
    

    Then on the front-end, we have something similar albeit with a different parent selector, as body.mce-content-body is exclusive to the backoffice. The trick here is that you need to wrap the rendered content (from the RTE) in some predefined class. In the example below, I edit the /Views/Partials/Grid/Editors/Rte.cshtml partial to add a custom wrapper:

    <div class="rte-wrapper">
        @Html.Raw(TemplateUtilities.ParseInternalLinks(Model.value.ToString()))
    </div>
    

    Then I add the following rules to my front-end css:

    .rte-wrapper img {
        margin-bottom: 1.777em;
    }
    
    .rte-wrapper img[style*="right"] {
        margin-left: 1.5em;
    }
    
    .rte-wrapper img[style*="left"] {
        margin-right: 1.5em;
    }
    

    Again, this applies margin to ALL images in an RTE with left or right alignment and does not allow for editor adjustment. One would think that this would be trivial by allowing editors to assign a class (or format) to an image, but I have yet to be able to do that gracefully with the latest version of Umbraco.

  • Steve Fabian 21 posts 102 karma points
    Jan 17, 2017 @ 18:48
    Steve Fabian
    0

    Thanks Matt!

Please Sign in or register to post replies

Write your reply to:

Draft