Skip to content

Commit 05fb929

Browse files
committed
Update img.style introduction
1 parent 7b84732 commit 05fb929

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed
+32-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
11
---
2-
title: styling <img> elements and example layouts
3-
description: styling <img> elements and example layouts
2+
title: New CSS features for images
3+
description: New CSS features for images
44
sidebar_sort_priority: 1000
55
date_published: '2023-03-29'
6-
date_modified: '2023-03-31'
6+
date_modified: '2024-02-07'
77
---
88

9-
# Styling `<img>` elements and example layouts
9+
Modern CSS empowers developers with concise, effective tools for robust image handling:
1010

11-
## Styling `<img>` elements
11+
- **Aspect Ratio:**
12+
The `aspect-ratio` property enforces fixed proportions, stabilizing layouts by preventing unexpected shifts while images load.
13+
```css
14+
.container {
15+
aspect-ratio: 16/9;
16+
}
17+
```
1218

13-
TODO:
19+
- **Object Fit & Object Position:**
20+
Use `object-fit` (e.g., `cover`, `contain`) and `object-position` to precisely control image scaling and alignment within their containers, eliminating awkward cropping or distortion.
21+
```css
22+
img {
23+
object-fit: cover;
24+
object-position: center;
25+
}
26+
```
27+
28+
- **Image-Set for Resolution Adaptability:**
29+
The `image-set()` function offers resolution switching for background images, ensuring optimal clarity on high-DPI devices.
30+
```css
31+
.hero {
32+
background-image: image-set(url("hero.png") 1x, url("[email protected]") 2x);
33+
}
34+
```
35+
36+
- **Additional Enhancements:**
37+
`image-rendering` fine-tunes scaling algorithms for crisp output (ideal for pixel art), while `filter` enables dynamic visual effects directly in CSS.
38+
39+
These features significantly streamline image presentation, reducing reliance on JavaScript hacks and complex workarounds, thus markedly easing everyday development tasks.

0 commit comments

Comments
 (0)