Design comparison
Solution retrospective
I feel very uncomfortable manipulating background and images. So please help improve my skill in images and background-images.
Community feedback
- @krushnasinnarkarPosted 4 months ago
Hi @Ridwan10000,
Congratulations on successfully completing the challenge!
As you asked about improving your skills with backgrounds in CSS, here are some tips and examples to help you get more comfortable:
1.
background-size
: Controls the size of the background image.auto
: Default. The background image retains its original size.cover
: Scales the image to cover the entire element, potentially cropping parts of it.contain
: Scales the image to fit within the element while maintaining its aspect ratio, potentially leaving empty space.length
: Specifies exact sizes (e.g.,100px 50px
), where the first value is the width and the second is the height.
/* Cover the entire element */ .element { background-image: url('path/to/image.jpg'); background-size: cover; }
2.
background-repeat
: Controls how the background image repeats.repeat
: Default. The background image repeats both horizontally and vertically.repeat-x
: Repeats the image only horizontally.repeat-y
: Repeats the image only vertically.no-repeat
: The image does not repeat; only one instance is shown.
/* No repeat */ .element { background-image: url('path/to/image.jpg'); background-repeat: no-repeat; }
3.
background-position
: Sets the position of the background image.- Keywords:
top
,right
,bottom
,left
,center
- Percentage: e.g.,
50% 50%
(center of the element) - Length: e.g.,
10px 20px
(offset from the top-left corner)
/* Center the image */ .element { background-image: url('path/to/image.jpg'); background-position: center; }
4.
background-attachment
: Specifies whether the background image scrolls with the content or stays fixed.scroll
: The background image scrolls with the content. This is the default value.fixed
: The background image is fixed relative to the viewport and does not scroll with the content.local
: The background image scrolls with the element’s content (useful for elements with overflow).
/* Background scrolls with the content */ .element { background-image: url('path/to/image.jpg'); background-attachment: scroll; }
5.
background-origin
: Specifies the positioning area of the background image relative to the element's box model.padding-box
: The background image is positioned relative to the padding box of the element (default).border-box
: The background image is positioned relative to the border box of the element.content-box
: The background image is positioned relative to the content box of the element.
/* Background image positioned relative to the padding box (default) */ .element { background-image: url('path/to/image.jpg'); background-origin: padding-box; }
6.
background-clip
: Specifies the painting area of the background.border-box
: The background extends to the border box (covers padding and border).padding-box
: The background extends only to the padding box (covers padding but not the border).content-box
: The background extends only to the content box (covers content but not the padding or border).
/* Background extends to the border box */ .element { background-color: #f0f0f0; background-clip: border-box; }
Combining Properties: You can combine these properties to achieve different effects. For example:
.element { background-image: url('path/to/image.jpg'); background-size: cover; background-repeat: no-repeat; background-position: center; background-attachment: fixed; background-origin: border-box; background-clip: content-box; }
This combination ensures that the background image covers the element without repeating, stays fixed during scroll, and is clipped to the content box.
Try experimenting with these properties in small projects or playgrounds like CodePen to see how they work in different scenarios. The more you practice, the more comfortable you'll become with manipulating backgrounds and images.
Additional Fix
For the Order Summary component’s background, you can use:
body { background-image: url('path/to/your-image.jpg'); background-repeat: no-repeat; background-size: 100%; background-color: hsl(225, 100%, 94%); }
This will ensure the background image does not repeat and covers the element properly.
I hope you find this helpful, and I would greatly appreciate it if you could mark my comment as helpful if it was.
Feel free to reach out if you have more questions or need further assistance.
Happy coding!
Marked as helpful1
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord