I’m trying to build a website which uses a background image with Bootstrap 4. I want the image to resize but unfortunately it focuses at different points on the image as it hits the breakpoints not really centering the image. Should I use resized images via photoshop or resize images via css resizing/shrinking the image. i.e. How do I get background image to stay at the center of the screen. sample of the media query code below: (initial image size is 2000px x 1333px. Thanks!
.landpage-img {
background: url(../img/bg-neon-01-2000x1333.jpg) no-repeat center center fixed;
}
2
Answers
You can make parent query
And
And your image will be in the middle of parrent selector.
You can either use
background-size: cover;
orbackground-size: contain;
.Like so:
background-size: contain;
maintains the proportions of the image whilebackground-size: cover;
is designed to cover things completely even if the image needs to be cropped a little. So, you’ll probably want to usebackground-size: cover;
most of the time.