I was looking for it forever, and I finally figured it out. However, this is only a solution for mobile devices. (Sorry to restore the old post):
@media screen and (orientation:portrait) { .box{ background-size: auto 100%; } } @media screen and (orientation:landscape) { .box{ background-size: 100% auto; } }
(This is written for images that are wider than they are long. To switch it, flip 100% and auto .) There are two parts. The first part includes @media screen and (orientation:landscape or portait) . It displays different images based on different screen orientations. The second part is more interesting: 100% width or length fills the image in width or length, and automatically just makes the image correctly scaled. Thus, if your image is longer than it is wide, in portrait mode it is filled with a longer side, thereby having a cover effect (and vice versa).
addcn source share