Switching ratio on small screens

Created on 10 October 2022, about 2 years ago
Updated 19 June 2024, 6 months ago

Problem/Motivation

In some cases, we have to switch the image ratio on small screens.

Steps to reproduce

One of these cases:
If there is an image with ratio 16:9 on desktop,
And we want to make it 3:4 on mobile.
Until now, there is no solution for this case.
It will be a great feature if it's added.

Proposed resolution

Suggesting that breakpoints field settings could be managed in the drimage widget:

  • List of breakpoints to select from in the widget settings.
  • Have a shape config option for each breakpoints (Scale, Ratio ).
  • Load the breakpoints in the Drupal Settings to be used.
  • The field formatter can manage to have the list of option listed in the data-set for JavaScript to use it.
  • Switch in the render with JavaScript to the other shape ratio.

Having a hint of a good solution with "Using attr to set css variable inline"

Example of a Custom responsive ratios developed Bootstrap Utility Classes

āœ… Released Bootstrap Ratio Utilities 1.0.2

https://github.com/Vardot/bootstrap-ratio-utilities#readme

Having Two Bootstrap Ratio Utilities

Responsive ratio utility

Ratio Utility with responsive options, which needed for switching ratios for media breakpoints.

Adds (-sm, -md, -lg, -xl, -xxl) to ratio classes to change the ratio for that brackpoint.
Use the normal ration classes for mobiles which less than -sm

Flip Ratio Utility

Flip Ratio Utility, which needed for flipping ratios for media breakpoints.

Adds (-flip-xs, -flip-sm, -flip-md, -flip-lg, -flip-xl, -flip-xxl) to ratio classes to change the ratio for that brackpoint
Use the -flip-xs ratio classes for mobiles which less than -flip-sm or -sm in case of using both ratio utilities at the same time

Override aspect ratios array to add more ratios.

// Override bootstrap 5 variables
// ----------------------------------------------------------------

// See more about override Bootstrap 5 variables here:
// https://getbootstrap.com/docs/5.0/customize/sass
// https://github.com/twbs/bootstrap/blob/v5.2.3/scss/_variables.scss

// Override aspect ratios array to add more ratios.
$aspect-ratios: (
  "1x1": 100%,
  "2x1": calc(1 / 2 * 100%),
  "3x1": calc(1 / 3 * 100%),
  "4x1": calc(1 / 4 * 100%),
  "4x3": calc(3 / 4 * 100%),
  "16x9": calc(9 / 16 * 100%),
  "21x9": calc(9 / 21 * 100%),
);

Remaining tasks

User interface changes

API changes

Data model changes

āœØ Feature request
Status

Closed: won't fix

Version

2.1

Component

Code

Created by

šŸ‡ÆšŸ‡“Jordan Abdullah Yassin

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024