If you're looking to have the background image fill the width without considering the height, you can achieve it with the following CSS:
.element-with-back-img{
background-repeat: no-repeat;
background-size: 100%;
}
However, this approach won't make the image cover the entire height of element-with-back-img as the height will be set to "auto".
To address this issue, you can use:
.element-with-back-img{
background-repeat: no-repeat;
background-size: 100% 100%;
}
With this solution, the image will fill both the width and height of element-with-back-img, but keep in mind that if there are differences in proportions between element-with-back-img and the image, the image will adjust its proportions to fit.
I suggest using:
.element-with-back-img{
background-repeat: no-repeat;
background-size: cover;
}
This method scales the background image to cover the entire background area, ensuring that all parts are visible within the specified dimensions. Some portions of the image may not be fully displayed depending on the positioning.
I hope this explanation proves helpful for your situation!
.test {
background-image: url(http://placekitten.com/1000/750);
background-size: 100%;
background-repeat: no-repeat;
background-color: lightblue;
height: 150px;
display: inline-block;
}
#test1 {
width: 200px;
}
#test2 {
width: 100px;
}
#test3 {
width: 300px;
}
.test:hover {
background-position: center center;
}
<div class="test" id="test1"></div>
<div class="test" id="test2"></div>
<div class="test" id="test3"></div>