The current CSS we use for captions in Drupal 8 is not responsive:

.caption {
  display: table;
}
.caption > * {
  display: block;
  max-width: 100%;
}
.caption > figcaption {
  display: table-caption;
  caption-side: bottom;
  max-width: none;
}

Although we have a max-width: 100% on child elements within a caption (which is a <figure> element in the markup), the parent element itself does not seem to be responsive.

There are a number of browser issues related to using display: table and tables themselves:

Comments

quicksketch created an issue. See original summary.

quicksketch’s picture

The reason we have this unusual CSS arrangement in the first place was because it was the only known way of centering an element without having a parent element that had text-align: center. Because in Drupal we don't have a reliable parent in our current filtering, we used this table-based CSS instead.

From the research I've done, it really seems like the only way to fix this is to use display: inline-block on the <figure> element and add a wrapper that has has text-align: center set on it in CSS. Then the inline-block element can easily be set to use max-width: 100%, and then the whole figure and image within it becomes responsive.

wim leers’s picture

That's unfortunate :(

Thank you very much for sharing this research!

quicksketch’s picture

Well, we successfully made figures and images responsive in Backdrop, but now our caption text overflows the image width. :P

That's unfortunate :(

No kidding! This turns out to be a sort of tough nut to crack. I can't believe a responsive figure and caption would be so hard. We're working on solving this later issue at https://github.com/backdrop/backdrop-issues/issues/1200

wim leers’s picture

Thanks for pointing me there, just commented: https://github.com/backdrop/backdrop-issues/issues/1200#issuecomment-146... — basically, I can't reproduce the problem? (Or am probably overlooking something.)

tarekdj’s picture

Status: Active » Needs review
StatusFileSize
new489.08 KB
new186.84 KB
new177.57 KB
new164.05 KB
new208.47 KB
new1.03 KB

I noticed that <figure> is not responsive at all on FF 40 (Win 7). Attached a quick fix. Works for different browsers on Win 7 but needs tests for other plateforms

wim leers’s picture

Hm… interesting. It definitely used to be the case that that display: table-caption was absolutely essential for this to work at all. It seems that's no longer the case?

tarekdj’s picture

@Wim Leers: It may be essential for <table> caption (http://www.w3schools.com/tags/tag_caption.asp). I don't know if it's the case for <figure>

wim leers’s picture

W3Schools… you might as well stab me. :P


See #2014895-17: Image captions & alignment (for inline images) and #2014895-21: Image captions & alignment (for inline images), where this was introduced. It's copied from http://stackoverflow.com/a/13363408/80305. Apparently since then, somebody has reported the same problem there: http://stackoverflow.com/questions/10264463/can-a-figcaption-be-restrict... — but a solution was also posted there.

But AFAICT simply adding height: auto; already fixes it? See http://codepen.io/anon/pen/pjrYaN + https://github.com/backdrop/backdrop-issues/issues/1200#issuecomment-147...

tarekdj’s picture

hehe shame on me :)!
I noticed the height: auto; workaround but it works only for chrome (At least for me, it is broken on Firefox 40 - Windows 7)

wim leers’s picture

Damn, you're right. That's also what @quicksketch originally reported in the first place: https://bugzilla.mozilla.org/show_bug.cgi?id=975632.

wim leers’s picture

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wim leers’s picture

I wonder if we can use flexbox to solve this? 80% of the global audience supports it unprefixed according to http://caniuse.com/flexbox.

So then we can continue to rely on the existing CSS as a fallback, but solve it for modern browsers (i.e. the 80%).

piatachki’s picture

Thank you for patch. Before images with caption show with original width and i must use width = 700px. Now CSS .img {width: 100%, heigth: auto} is working. Why this patch not included at 8.1.x?

wim leers’s picture

Title: The CSS used for Filter/Editor captions is not responsive » [upstream][Firefox] The CSS used for Filter/Editor captions is not responsive
Issue tags: +Needs upstream bugfix

#15: because it only fixes it in the case of a captioned image, not in the case of captioned blockquotes, code examples, etc.

Also, quoting @quicksketch from the Backdrop issue: https://github.com/backdrop/backdrop-issues/issues/1200#issuecomment-212...

It looks like the original bug has been fixed in Firefox (though not in a current stable yet): https://bugzilla.mozilla.org/show_bug.cgi?id=975632

Firefox is currently version 45.0. It's fixed in 46.0 and 47.0.

So… it looks like once Firefox 47 is rolled out, this problem will finally disappear automatically :)

wim leers’s picture

Firefox 47 has been rolled out. Does that mean we can close this?

(Cross-posted to https://github.com/backdrop/backdrop-issues/issues/1200#issuecomment-226....)

joginderpc’s picture

Status: Needs review » Reviewed & tested by the community

Yes i could also say that we can close this as i tested this and updating status.

wim leers’s picture

Cool! :)

Let's first await feedback from the Backdrop team before really marking this fixed.

wim leers’s picture

Status: Reviewed & tested by the community » Needs review

Moving to "needs review", because core committers can't actually commit anything here.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

quicksketch’s picture

Status: Needs review » Closed (outdated)

I've confirmed that the problem seems to have "resolved itself" in the latest Firefox versions. Over in Backdrop-land we need to revert back to the table-CSS approach, but the latest D8 still uses the original approach (which is now working in Firefox).

So I think this can be closed, no changes necessary here.