Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

css - Resizing background-image always proportionally to scale with a center point

I want to be able to reproduce the behavior of this website's image when resizing.

It seems like the background-image has a center point where the image start to crop when it cannot keep its proportion scale.

Here is an example:

http://themes.evgenyfireform.com/wp-jad/

For now my background has the following css:

#bg {
    position: fixed;
    top: 0;
    left: 0px;
    width:100%;
}

The problem is that it's fixed and I want it to crop when the image can't be scale.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You are looking for this combination:

background-position:50% 50%;  /* Sets reference point to scale from */
background-size:cover;        /* Sets background image to cover entire element */

Working sample fiddle here.

Note that this is not supported by IE8 and will require JS hackery there if you need IE8 or older to be supported.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...