marp-team / marp-core

The core of Marp converter
MIT License
800 stars 132 forks source link

Update display style of built-in themes container #382

Closed yhatt closed 2 months ago

yhatt commented 2 months ago

Closes #372.

The default slide container is now the block element.

Modern browsers can be centering child elements by using align-content: center. This change will reduce confusion about properties that are incompatible with Flexbox, such as float: right, columns: 2, and so on.

Breaking change

Safe centering

In this update, we have also adopted "safe centering", that may break the layout of slides for existing presentations. https://developer.mozilla.org/en-US/docs/Web/CSS/align-content#safe

section {
  /* Marp Core v4 adopts safe centering by default */
  align-content: safe center;
}

Behavior

Let’s consider a scenario that the slide content will overflow beyond the padding of the slide container.

Until Marp Core v3, the content is always vertically centered. If the slide has a lot of content, it will overflow from both the top and bottom of the slide container.

In Marp Core v4 and later, the content no longer overflows beyond the safe padding at the top. Contents will consistently overflow from the bottom.

Marp Core v3: Unsafe centering Marp Core v4+: Safe centering
unsafe-centering safe-centering

This change will be a breaking change for users who have relied on the previous centering, but we believe it is worth making this adjustment to support the creation of higher-quality presentations.

Use unsafe centering

If you want to use unsafe centering, you can tweak with the following CSS:

<style>
  section { align-content: unsafe center; }
</style>
<style>
  section.lead { align-content: unsafe center; }
</style>

Unsafe centering always will center the slide contents even if overflowed, like before. The slide container is still the block element.

Revert to flex container (v3's default)

Instead of unsafe centering, you can also revert the slide container to Flexbox as same as Marp Core v3. Just set display: flex to the slide container:

<style>
  section { display: flex; }
</style>
<style>
  section.lead { display: flex; }
</style>