1. Background Position Offset
Positioning a background graphic is straightforward and something you’re likely familiar with already. If we want to position the background to the bottom right of the element, we apply bottom right to background-position. For example:
- #workspace {
- width: 100%;
- max-width: 668px;
- height: 400px;
- background-color: #525d62;
- background-image: url(images/macbook.png);
- background-repeat: no-repeat;
- background-position: right bottom;
- }
- #workspace {
- width: 100%;
- max-width: 668px;
- height: 400px;
- background: #525d62 url(images/macbook.png) no-repeat right bottom;
- }
- #workspace {
- width: 100%;
- max-width: 668px;
- height: 400px;
- background-color: #525d62;
- background-image: url(images/macbook.png);
- background-repeat: no-repeat;
- background-position: right 30px bottom 20px;
- }
bottom
, top
, right
, left
) can be defined in any order, but the offset length must be defined after each background position.![]() |
![]() |
![]() |
2. Multiple Background Images
The background property also allows us to add multiple background images. Therefore, let's extend our previous example with more stuff and gadgets.
![]() |
![]() |
![]() |
- #workspace {
- height: 400px;
- background-color: #525d62;
- background-image:
- url(images/macbook.png),
- url(images/mouse.png),
- url(images/hdd.png),
- url(images/phone.png),
- url(images/ipad.png),
- url(images/coffee.png),
- url(images/camera.png);
- background-repeat: no-repeat;
- background-position:
- 50% 50%, /* macbook.png */
- 75% 295px, /* mouse.png */
- 75% 230px, /* hdd.png */
- 96% 240px, /* phone.png */
- 20% 250px, /* ipad.png */
- 22% 190px, /* coffee.png */
- 7% 280px; /* camera.png */
- }
Each pair of values represents coordinates from the top left of the container element, to the top left of the image. For example, the top left of the camera image is 280px from the top of the container, then 7% of the available width across from the left.
![]() |
![]() |
If you found this post interesting, follow and support us.
Suggest for you:
CSS: Foundation classes on CSS
CSS Animations: Create Amazing Effects on Your Website
Coding Made Easy: HTML & CSS For Beginners
Bootstrap 4 Rapid web development framework HTML CSS JS
No comments:
Post a Comment