0

My scenario:

  • I have an image of size 1900 x 1600 pixels.
  • I have a div of size 200 x 150 pixels.

I have resized the image using the following CSS:

max-width:300px;
max-height:300px;

The height will be kept in proportion, so in this example it will be 252 px.

How can I center the image in the div? I mean something like:

background-position: center center;

Is this sort of thing possible with CSS 2?

4

2 回答 2

2

You mean

background:url("test.png");
background-size: 300px auto;
background-position: center center;

?

于 2012-04-10T19:02:29.483 回答
0

To center the DIV within an element, you would set a width and margin with the left and right margins set to auto:

div { margin: 0 auto; width: 300px; }

于 2012-04-10T19:02:41.360 回答