CSS aspect-ratio property
News / Jan 31, 2021
CSS aspect-ratio
property - the most awaited feature is now shipped in the new Chrome 88 along with other major updates.
With aspect ratio, we can define an element's dimension proportionally.
A quick example to make a square box with aspect-ratio:
.sizing-1x1 {
aspect-ratio: 1/1;
background: yellow;
}
Another example:
.sizing-16x9 {
aspect-ratio: 16/9; /* a rectangle */
background: yellow;
}
Cool. But there are few things you must know -
- If height and width are defined, the aspect-ratio will be ignored.
- If either height or width is defined then the other is calculated from the aspect ratio.
We can use @supports not
for other browsers if the aspect ratio is not supported.
@supports not (aspect-ratio: 1 / 1) {
.sizing-1x1 {
width: 200px;
height: 200px;
}
}
Check this CodePen demo by Una Kravets.
Read New in Chrome 88
Latest
SOLID Principles: A Comprehensive Guide with Examples
Dec 22, 2024
React useEffect, useMemo, and useCallback: A Comprehensive Guide
Nov 23, 2024
React Component Structure, Composition, HOCs and Optimization with Examples
Oct 4, 2023
How to copy text to the clipboard in React.js
Sep 29, 2023
News
Pure html popover API is coming in Chromium 114
Sep 24, 2023
GitHub and OpenAI launch Copilot - an AI pair programmer
Jul 1, 2021
CSS aspect-ratio property
Jan 31, 2021
AWS UI - a collection of React components
Jan 20, 2021
Featured
SOLID Principles: A Comprehensive Guide with Examples
Dec 22, 2024
React useEffect, useMemo, and useCallback: A Comprehensive Guide
Nov 23, 2024
Axios Interceptors in a React application
May 27, 2023
Mastering Laravel: Exploring the Power of implode() and explode() Functions for String Manipulation
May 22, 2023