Example CSS for the CKEditor Enhanced Image plugin

This is a community-contributed tutorial. This tutorial is over a year old and may not apply to your version of Concrete CMS.
Jul 17, 2017

http://ckeditor.com/addon/image2
Dashboard > System & Settings > Basics > Rich Text Editor > Enhanced Image

Enhanced Image Features:

  • allows for adding image captions (that will not be separated from the image when its location changes)
  • has all advantages of widgets, i.e. you can treat the image and its caption as one entity and select, delete, or move it in the editor content area as a whole
  • supports drag and drop for changing image position
  • provides image alignment CSS classes
  • includes hassle-free "click and drag" resizing

The Enhanced Image Plugin Compared to the Image Plugin:

The Enhanced Image plugin assigns classes for alignment and captions and adds the HTML for the captions. It is up to the individual or theme maker to write the CSS for these classes.

Alignment Classes

Left - the img tag is assigned the class content-editor-image-left.
Center - the picture tag is wrapped in a p tag with the class content-editor-image-center.
Right - the img tag is assigned the class content-editor-image-right.

Image Captions

When enabling image captions, the picture tag is wrapped in a figure tag with the class content-editor-image-captioned and an alignment class if an alignment has been selected. A figcaption tag is added after the picture tag with the default text of "Caption".

Example: captioned image with right alignment

<figure class="content-editor-image-captioned content-editor-image-right">
    <picture>
        <!--[if IE 9]><video style='display: none;'><![endif]-->
        <source srcset="/my_site/application/files/thumbnails/large/6015/0024/5193/happy_cupcake.jpg" media="(min-width: 900px)">
        <source srcset="/my_site/application/files/thumbnails/medium/6015/0024/5193/happy_cupcake.jpg" media="(min-width: 768px)">
        <source srcset="/my_site/application/files/thumbnails/small/6015/0024/5193/happy_cupcake.jpg">
        <!--[if IE 9]></video><![endif]--><img src="/my_site/application/files/thumbnails/small/6015/0024/5193/happy_cupcake.jpg" alt="happy_cupcake.jpg">
    </picture>
    <figcaption>Caption</figcaption>
</figure>

Example Alignment CSS

Left

.content-editor-image-left {
    float: left;
    margin: 10px 20px 10px 0;
}

Center

.content-editor-image-center img {
    display: block;
    margin-left: auto;
    margin-right: auto;
}

Center (preserve styling when editing content)

.cke_widget_image .content-editor-image-center {
    margin: 10px 0;
    text-align: center;
}

Right

.content-editor-image-right {
    float: right;
    margin: 10px 0 10px 20px;
}

Example Alignment and Caption CSS

Standard

.content-editor-image-captioned {
    display: table;
    margin-bottom: 10px;
    margin-top: 10px;
}

.content-editor-image-captioned.content-editor-image-left {
    float: left;
    margin-left: 0;
    margin-right: 20px;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-left {
    float: left;
    margin: 10px 20px 10px 0;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-left .content-editor-image-captioned {
    margin: 0;
}

div.content-editor-image-center .content-editor-image-captioned {
    margin: 20px auto;
}

.content-editor-image-captioned.content-editor-image-right {
    float: right;
    margin-left: 20px;
    margin-right: 0;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-right {
    float: right;
    margin: 10px 0 10px 20px;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-right .content-editor-image-captioned {
    margin: 0;
}

.content-editor-image-captioned figcaption {
    caption-side: bottom;
    display: table-caption;
    padding-top: 10px;
    padding-bottom: 10px;
}

Standard with Background Color

.content-editor-image-captioned {
    display: table;
    margin-bottom: 10px;
    margin-top: 10px;
}

.content-editor-image-captioned.content-editor-image-left {
    float: left;
    margin-left: 0;
    margin-right: 20px;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-left {
    float: left;
    margin: 10px 20px 10px 0;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-left .content-editor-image-captioned {
    margin: 0;
}

div.content-editor-image-center .content-editor-image-captioned {
    margin: 20px auto;
}

.content-editor-image-captioned.content-editor-image-right {
    float: right;
    margin-left: 20px;
    margin-right: 0;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-right {
    float: right;
    margin: 10px 0 10px 20px;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-right .content-editor-image-captioned {
    margin: 0;
}

.content-editor-image-captioned figcaption {
    background: #f5f5f5;
    border: 1px solid lightgray;
    caption-side: bottom;
    display: table-caption;
    padding: 10px;
}

Overlay with Semi-transparent Background Color

.content-editor-image-captioned {
    display: inline-block;
    margin-bottom: 10px;
    margin-top: 10px;
    position: relative;
}

.content-editor-image-captioned.content-editor-image-left {
    float: left;
    margin-left: 0;
    margin-right: 20px;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-left {
    float: left;
    margin: 10px 20px 10px 0;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-left .content-editor-image-captioned {
    margin: 0;
}

div.content-editor-image-center {
    text-align: center;
}

div.content-editor-image-center figcaption {
    text-align: left;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-center {
    text-align: center;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-center figcaption {
    text-align: left;
}

.content-editor-image-captioned.content-editor-image-right {
    float: right;
    margin-left: 20px;
    margin-right: 0;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-right {
    float: right;
    margin: 10px 0 10px 20px;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-right .content-editor-image-captioned {
    margin: 0;
}

.content-editor-image-captioned figcaption {
    background: rgba(0, 0, 0, 0.5);
    bottom: 0;
    color: #fff;
    padding: 10px;
    position: absolute;
    width: 100%;
}

Hover Overlay with Semi-transparent Background Color

.content-editor-image-captioned {
    display: inline-block;
    margin-bottom: 10px;
    margin-top: 10px;
    position: relative;
}

.content-editor-image-captioned.content-editor-image-left {
    float: left;
    margin-left: 0;
    margin-right: 20px;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-left {
    float: left;
    margin: 10px 20px 10px 0;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-left .content-editor-image-captioned {
    margin: 0;
}

div.content-editor-image-center {
    text-align: center;
}

div.content-editor-image-center figcaption {
    text-align: left;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-center {
    text-align: center;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-center figcaption {
    text-align: left;
}

.content-editor-image-captioned.content-editor-image-right {
    float: right;
    margin-left: 20px;
    margin-right: 0;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-right {
    float: right;
    margin: 10px 0 10px 20px;
}

/*preserve styling when editing content*/
.cke_widget_image.content-editor-image-right .content-editor-image-captioned {
    margin: 0;
}

.content-editor-image-captioned figcaption {
    background: rgba(0, 0, 0, 0.5);
    bottom: 0;
    color: #fff;
    display: block;
    opacity: 0;
    padding: 10px;
    position: absolute;
    transition: opacity 250ms;
    width: 100%;
}

.content-editor-image-captioned:hover figcaption {
    opacity: 1;
}

Tips:

  • There are situations where the text is not lined up horizontally with the top of the image. When that happens you can add vertical space by adding a br tag (Shift+Enter keys) or p tag (Enter key).
  • When using floated images with text on narrow screens, the available area for text is just big enough for a few words or less. This makes for a challenging reading experience. This can be prevented by adding a media query and removing the float on the image. The screen width for the media query will depend on the size of the text.
  • To make images responsive, add this CSS:

    div.ccm-page img {
        height: auto;
        max-width: 100%;
    }
    
Recent Tutorials
Bi-directional Express associations
Dec 18, 2024
By myq.

Set up associations between Express entries in both directions

Display Express Data Across Multiple Sites
Dec 17, 2024
By myq.

A guide to configuring Express entities and the Express Entry List block to ensure proper data display across multiple sites.

Customize locale icons
Oct 29, 2024
By myq.

How to customize locale (language region) flags

Concrete CMS Caching Guide
Oct 16, 2024

An overview of types of caching in Concrete and considerations when using them.

Redirect all requests to HTTPS
Oct 9, 2024
By myq.

How to follow best practices for a secure web

Upgrade Concrete versions 9.3.1 and 9.3.2
Sep 10, 2024
By myq.

How to get past a bug in versions 9.3.1 and 9.3.2 that prevents upgrading the Concrete core through the Dashboard

Improvements?

Let us know by posting here.