sen2008
sen2008

Reputation: 13

CSS Can a background image fill its parent div to the left instead of right?

This isn't possible that I know of, but it would be incredibly useful if one of you fine folks has a solution for me. So, if an image does not have enough room to completely display, the right side of the image is cut off. Is it possible to have it instead cut off the left side of the image? My ultimate goal would be as the window size increases, the image fills in on the left side rather than on the right.

Upvotes: 0

Views: 920

Answers (2)

Gabriel Isenberg
Gabriel Isenberg

Reputation: 26341

The background-position property used in conjunction with background-size is probably what you are looking for:

background-position: right center; background-size: contain;

More information can be found here.

Upvotes: 4

aahhaa
aahhaa

Reputation: 2275

http://jsfiddle.net/kkf8u8u7/

I think this is what you are after, if you don't want the use background image

div {
  width:200px;
  height:300px;
  position:relative;
  overflow:hidden;
  display:block;
}
img {
  display:block;
  position:absolute;
}
#left {
  left:0px;
}
#right {
  right:0px;
}

Upvotes: 0

Related Questions