Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

full screen background with cover, but focus on a part of the image

I want a div to have a background image that covers the entire div but when the browser window size changes not to scale down too much but focus towards a point on the image.

A good example would be this, but instead when you make your window size smaller it would focus on the yellow sign instead of the middle of the image.

Is there a plugin or tutorial for this sort of thing? I'm sure that with jquery and css image sprites I can come up with something but I would rather use a proven plugin or technique instead of hacking something together.

like image 803
Timotheus Avatar asked Jul 18 '13 11:07

Timotheus


People also ask

How do I make an image occupy a whole div?

To auto-resize an image or a video to fit in a div container use object-fit property. It is used to specify how an image or video fits in the container. object-fit property: This property is used to specify how an image or video resize and fit the container.

How do you make a BG picture fit the screen?

Using CSS, you can set the background-size property for the image to fit the screen (viewport). The background-size property has a value of cover . It instructs browsers to automatically scale the width and height of a responsive background image to be the same or bigger than the viewport.

What does background-size cover do?

If the background-size is contain or cover : While preserving its intrinsic proportions, the image is rendered at the largest size contained within, or covering, the background positioning area. If the image has no intrinsic proportions, then it's rendered at the size of the background positioning area.

How do I make a background image opaque in CSS?

There's no CSS property that you can use to change the opacity of only the background image. Unlike background colors, which allow you to adjust the alpha channel to control opacity, it simply doesn't exist for the background-image property.


2 Answers

Well I guess this was far from as difficult as I had imagined, but the behaviour I wanted can be achieved simply by doing this:

{
background: url('http://farm8.staticflickr.com/7218/7289572558_44c110c510_h.jpg') no-repeat 95% 50%;
min-height: 100%;
background-size: cover;
}
like image 123
Timotheus Avatar answered Oct 22 '22 19:10

Timotheus


You could add background-position and other editing..

This way should adjust ..

background: url('IMG.PNG') no-repeat center center;
min-height: 100%;
background-size: cover;

Offering positional support

background-position-x: -100px;
background-position-y: 100px;

You will need to consider the background size though as you will be cropping.

If you where to consider not limiting the size of your BG to the Document size you could position it (providing the image was greater than the users screen) and then overflow:hidden to remove those scrollbars but still not the most elegant way.

like image 1
Pogrindis Avatar answered Oct 22 '22 20:10

Pogrindis