Skip to content

Add aspect ratio selector to Cover BlockΒ #23092

@markhowellsmead

Description

@markhowellsmead

The current Cover Block has a setting through which the user can choose a minimum height for the Block. The standard is 430px. However, this minimum height applies across all screen sizes.

An alternative solution which we use in our projects is to allow the Cover Block to receive an aspect ratio, by way of a custom control and custom class names on the container DIV. With this setting, the user can choose an aspect ratio of (say) 2:1, which will ensure that the block remains consistently proportioned across all screen sizes.

Our CSS is as follows. (The standard feature using min-height still applies, but only if the min-height is set explicitly in the Editor by way of dragging the height, or by adding a value to the min-height input field.)

.wp-block-cover {

	&[class*='is-style-aspect'] {
		min-height: 0;
	}

	&.is-style-aspect-21::after {
		content: '';
		display: block;
		padding-bottom: percentage(1/2);
	}

	&.is-style-aspect-31::after {
		content: '';
		display: block;
		padding-bottom: percentage(1/3);
	}

	&.is-style-aspect-41::after {
		content: '';
		display: block;
		padding-bottom: percentage(1/4);
	}

	&.is-style-aspect-169::after {
		content: '';
		display: block;
		padding-bottom: percentage(9/16);
	}

	&.is-style-full-height::after {
		content: '';
		display: block;
		padding-bottom: 100vh;
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    CSS StylingRelated to editor and front end styles, CSS-specific issues.[Block] CoverAffects the Cover Block - used to display content laid over a background image

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions