Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you make a background image to adjust it's size to the containing element?

Check the rounded corners of the main tabs in this site Those are background images with width of 440px, and still it adjusts to the containing element without loosing the rounded edges.

like image 697
Itay Moav -Malimovka Avatar asked Dec 20 '25 00:12

Itay Moav -Malimovka


1 Answers

Looks like the list item and anchor both have the same background image, just at different offsets.

The image is set as the background for each of those elements. The anchor is set to show the left most portion of the image while the list item is set the right most portion with right padding just wide enough for the image to peek through. The technique is known as Sliding Doors. Here are the links collected from the other answers:

  • A List Apart's Sliding Doors Part 1
  • A List Apart's Sliding Doors Part 2
  • A CSS2 tutorial
  • A CSS3 tutorial

Thanks Mariuz and Darko Z.

like image 110
Jonathon Watney Avatar answered Dec 21 '25 13:12

Jonathon Watney



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!