Skip to content

Commit c19a4e7

Browse files
JeanMechedylhunn
authored andcommitted
docs: Move the background image migration to its own section. (#56588)
PR Close #56588
1 parent 1d28fbb commit c19a4e7

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

adev/src/content/guide/image-optimization.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ In addition to optimizing the loading of the LCP image, `NgOptimizedImage` enfor
1717
* Warning if `width` or `height` have been set incorrectly
1818
* Warning if the image will be visually distorted when rendered
1919

20+
If you're using a background image in CSS, [start here](#how-to-migrate-your-background-image).
21+
2022
**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.**
2123

2224
## Getting Started
@@ -112,6 +114,19 @@ You can also style your image with the [object-position property](https://develo
112114

113115
IMPORTANT: For the "fill" image to render properly, its parent element **must** be styled with `position: "relative"`, `position: "fixed"`, or `position: "absolute"`.
114116

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+
115130
## Using placeholders
116131

117132
### Automatic placeholders
@@ -385,15 +400,7 @@ Note that in the above example, we've invented the 'roundedCorners' property nam
385400

386401
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.
387402

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.
397404

398405
### Why can't I use `src` with `NgOptimizedImage`?
399406

0 commit comments

Comments
 (0)