Skip to content

Commit

Permalink
Fix image caption margins
Browse files Browse the repository at this point in the history
In #7721, we introduced a new wrapping div for the image block.

As part of that, the margin for the figure was also zeroed out. This is what caused the regression.

Most themes don't touch the figure, and it's born with 1em margin top and bottom. In testing, however, we noticed that some themes _do_ provide figure styles, and they zero them out.

As such, this PR fixes the regression by:

- Removing the regression. Situations with figures that worked prior to the regression will work the same.
- Adding comments to the code to prevent this from happening again.
- Adding an additional bottom margin to the caption style, to ensure themes that zero out the figure have some bottom margin.

This PR adds a 1em bottom margin to all captions. This margin collapses if the figcaption is inside a figure, but is still there in case it's inside a div.
  • Loading branch information
jasmussen committed Sep 3, 2018
1 parent c9668e9 commit 90392d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions edit-post/assets/stylesheets/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@

@mixin caption-style() {
margin-top: 0.5em;
margin-bottom: 1em;
color: $dark-gray-300;
text-align: center;
font-size: $default-font-size;
Expand Down
10 changes: 7 additions & 3 deletions packages/block-library/src/image/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
.aligncenter,
&.is-resized {
display: table;
margin: 0;

// The figure is born with left and right margin.
// We remove this by default, and then customize it for left, right, and center.
margin-left: 0;
margin-right: 0;

> figcaption {
display: table-caption;
Expand All @@ -38,9 +42,9 @@
margin-left: 1em;
}

// Centered images.
.aligncenter {
margin: 0 auto;
margin-left: auto;
margin-right: auto;
}

// Supply caption styles to images, even if the theme hasn't opted in.
Expand Down

0 comments on commit 90392d8

Please sign in to comment.