You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: adev/src/content/guide/image-optimization.md
+16-9Lines changed: 16 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,8 @@ In addition to optimizing the loading of the LCP image, `NgOptimizedImage` enfor
17
17
* Warning if `width` or `height` have been set incorrectly
18
18
* Warning if the image will be visually distorted when rendered
19
19
20
+
If you're using a background image in CSS, [start here](#how-to-migrate-your-background-image).
21
+
20
22
**Note: Although the `NgOptimizedImage` directive was made a stable feature in Angular version 15, it has been backported and is available as a stable feature in versions 13.4.0 and 14.3.0 as well.**
21
23
22
24
## Getting Started
@@ -112,6 +114,19 @@ You can also style your image with the [object-position property](https://develo
112
114
113
115
IMPORTANT: For the "fill" image to render properly, its parent element **must** be styled with `position: "relative"`, `position: "fixed"`, or `position: "absolute"`.
114
116
117
+
## How to migrate your background image
118
+
119
+
Here's a simple step-by-step process for migrating from `background-image` to `NgOptimizedImage`. For these steps, we'll refer to the element that has an image background as the "containing element":
120
+
121
+
1) Remove the `background-image` style from the containing element.
122
+
2) Ensure that the containing element has `position: "relative"`, `position: "fixed"`, or `position: "absolute"`.
123
+
3) Create a new image element as a child of the containing element, using `ngSrc` to enable the `NgOptimizedImage` directive.
124
+
4) Give that element the `fill` attribute. Do not include a `height` and `width`.
125
+
5) If you believe this image might be your [LCP element](https://web.dev/lcp/), add the `priority` attribute to the image element.
126
+
127
+
You can adjust how the background image fills the container as described in the [Using fill mode](#using-fill-mode) section.
128
+
129
+
115
130
## Using placeholders
116
131
117
132
### Automatic placeholders
@@ -385,15 +400,7 @@ Note that in the above example, we've invented the 'roundedCorners' property nam
385
400
386
401
The NgOptimizedImage does not directly support the `background-image` css property, but it is designed to easily accommodate the use case of having an image as the background of another element.
387
402
388
-
Here's a simple step-by-step process for migrating from `background-image` to `NgOptimizedImage`. For these steps, we'll refer to the element that has an image background as the "containing element":
389
-
390
-
1) Remove the `background-image` style from the containing element.
391
-
2) Ensure that the containing element has `position: "relative"`, `position: "fixed"`, or `position: "absolute"`.
392
-
3) Create a new image element as a child of the containing element, using `ngSrc` to enable the `NgOptimizedImage` directive.
393
-
4) Give that element the `fill` attribute. Do not include a `height` and `width`.
394
-
5) If you believe this image might be your [LCP element](https://web.dev/lcp/), add the `priority` attribute to the image element.
395
-
396
-
You can adjust how the background image fills the container as described in the [Using fill mode](#using-fill-mode) section.
403
+
For a step-by-step process for migration from `background-image` to `NgOptimizedImage`, see the [How to migrate your background image](#how-to-migrate-your-background-image) section above.
397
404
398
405
### Why can't I use `src` with `NgOptimizedImage`?
0 commit comments