Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h1>Answer</h1> <p>You have multiple options:</p> <ol> <li><code>background-size: 100% 100%;</code> - image gets stretched (aspect ratio may be preserved, depending on browser)</li> <li><code>background-size: contain;</code> - image is stretched without cutting it while preserving aspect ratio</li> <li><code>background-size: cover;</code> - image is completely covering the element while preserving aspect ratio (image can be cut off)</li> </ol> <p>/edit: And now, there is even more: <a href="https://alligator.io/css/cropping-images-object-fit" rel="noreferrer">https://alligator.io/css/cropping-images-object-fit</a></p> <h2><a href="https://codepen.io/alp82/pen/wqPaNe?editors=1100" rel="noreferrer">Demo on Codepen</a></h2> <h1>Update 2017: Preview</h1> <p>Here are screenshots for some browsers to show their differences.</p> <h2>Chrome</h2> <p><img src="https://i.stack.imgur.com/XgHeC.png" alt="preview background types chrome"></p> <hr> <h2>Firefox</h2> <p><img src="https://i.stack.imgur.com/JQ4n4.png" alt="preview background types firefox"></p> <hr> <h2>Edge</h2> <p><img src="https://i.stack.imgur.com/SgBvD.png" alt="preview background types edge"></p> <hr> <h2>IE11</h2> <p><img src="https://i.stack.imgur.com/WSd1V.png" alt="preview background types ie11"></p> <h1>Takeaway Message</h1> <h2><code>background-size: 100% 100%;</code> produces the least predictable result.</h2> <h1>Resources</h1> <ul> <li><a href="https://alligator.io/css/cropping-images-object-fit" rel="noreferrer">https://alligator.io/css/cropping-images-object-fit</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload