How to include right-aligned images in your content to go with your text without modifying the default content types or using features or custom modules
The Social Base and Social Blue themes lack some classes used by CK Editor to align inline content...
Just sharing how I solved this need, for anyone with a similar need or interest.
Before explaining, here's the result, just in case it's not clear:
A medium picture is embedded inline, aligned to the right of a paragraph, in this case the bio of a person described in the text.
See attached file

Or see it live at http://www.civ.do/team
1. First you need to add your own custom CSS file to the theme.
Under your Open Social root file go to the Social Blue Theme directory.
cd html/profiles/contrib/social/themes/socialblue
Edit socialblue.libraries.yml to have the team look for custom.css.
sudo nano socialblue.libraries.yml
And add assets/css/custom.css: {} under base assets, so that it looks like this:
# The SMACSS category "base" is loaded first.
base:
css:
base:
assets/css/base.css: {}
assets/css/custom.css: {}
2. Then create custom.css and add the required classes for achieving the desired look:
sudo nano assets/css/custom.css
Inside, paste:
/* ----------------------------------------------
CSS Alignment Classes used by CKEditor plugins
missing from OpenSocial Base and Blue Themes
---------------------------------------------- */
.align-right {
/* copied from bootstrap .pull-right
http://getbootstrap.com/css/#helper-classes-floats */
float: right;
}
.align-left {
/* copied from bootstrap .pull-left
http://getbootstrap.com/css/#helper-classes-floats */
float: left;
}
.align-center {
/* copied from bootstrap .center-block
http://getbootstrap.com/css/#helper-classes-center
*/
display: block;
margin-left: auto;
margin-right: auto;
}
/* ----------------------------------------------
Alignment of Inline Images and limiting caption
captions to the width of their images
---------------------------------------------- */
figure.align-right,
figure.align-left {
padding: 10px;
margin: 0px;
display: table;
}
figure.align-center {
padding: 10px;
display: table;
}
figure.align-right figcaption,
figure.align-left figcaption,
figure.align-center figcaption {
font-size: small;
text-align: center;
display: table-caption;
caption-side: bottom ;
margin-bottom: 5px;
}
Now you can simply embed images, align them and add captions to them using the regular WYSIWYG editor and without having to install or do anything else.
Do note that composer update will override these changes, so you will have to apply them again (changing socialblue.libraries.yml and creating assets/css/custom.css: {}) after an upgrade.
Hope these helps anyone.
PS: I have a copy of these on my personal sandbox notes sites, in case code looks broken here, at
http://www.codigoslibres.com/drupal/opensocial
PS: Maintainers are free to add this to any knowledge base and modify it if desired. I'd also be happy to provide a more detailed description if required to post it where it can help others.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 2890462-figures-7.patch | 11.54 KB | maikelkoopman |
| #2 | Screen Shot 2017-07-03 at 11.19.00.png | 101.91 KB | peter.polman |
| Screen Shot 2017-06-28 at 8.15.36 PM.png | 188.14 KB | Carlos Miranda Levy |
Comments
Comment #2
peter.polman commentedHey man! Thanks for contributing in our good idea's space!;)
I'd like to add this feature to socialbase's ckeditor library (socialbase/components/wysiwyg/ckeditor.scss), but I'm missing some responsive behaviour (see attachment)..
Would you be able to do the following:
- Add these styles to the ckeditor.scss file in the socialbase theme
- Add missing responsive behaviour (e.g 100% width om small screens or a smaller width of the image)
- Compile CSS asset with Gulp
- Create a patch of the diff.
We can then review the patch, merge it in the distro and credit your work:) Like to hear from you!
Comment #3
Carlos Miranda Levy commentedI'll work on it by the end of the week and report back :-)
Comment #4
peter.polman commentedCool! I see you've found our Slack channel already:) Feel free to send me a DM there if you need input.
Comment #5
Carlos Miranda Levy commentedI'm busy at Startup Weekend this weekend, but I promised something by the end of the week, so here it is.
Do keep in mind that my knowledge of responsive CSS is mostly from stackoverflow, inspect element and view source of other modules and themes, so there might be a more standard or proper way to achieve this.
I did test the outcome on Safari, Chrome, Firefox on a Mac and on Galaxy S7, iPhone 5 and 7" Kindle Fire and it looks fine.
The following css makes it responsive, so that when viewing the page on a small screen, the images are resized to the screen width and displayed centered with text flowing above and below them, and we also make the caption text smaller:
So, the complete css that needs to be added (in my case to custom.css), to support left-aligned, centered and right-aligned images inserted via CKEditor within the text is:
You can see it working on these 2 urls:
Basic page example: http://www.civ.do/team
User information example: http://www.relief20.com/carlos-miranda-levy/info
(just to make sure, css is being read regardless of content type)
Comment #6
jochemvn commentedComment #7
maikelkoopman commentedPR here be found here:
https://github.com/goalgorilla/open_social/pull/582
Comment #8
jochemvn commentedReviewed and merged. Will be part of the 1.6 release