Stretching and Scaling CSS Backgrounds
Question: How can you make a CSS background stretch or scale to fit its container?
Answer:
To achieve this, you can leverage the background-size property in CSS3.
#my_container { background-size: 100% auto; /* width and height, can be %, px or whatever. */ }
This property is supported by most modern browsers since 2012, enabling you to control both the width and height of your background. By setting the width to 100%, you ensure that the background spans the entire container's width. The auto setting for the height will automatically adjust to maintain the background's aspect ratio.
The above is the detailed content of How Can I Stretch or Scale a CSS Background to Fit Its Container?. For more information, please follow other related articles on the PHP Chinese website!