/ Published in: CSS
"Contain" maintains aspect ratio of the image while giving a full screen - will scale down but wont scale up beyond 100% of its own dimensions and doesn't repeat by default
"Cover" will crop either crop or stretch the image to cover the full screen - seems to be setting image to 100% of screen size regardless of browser window size
"Cover" will crop either crop or stretch the image to cover the full screen - seems to be setting image to 100% of screen size regardless of browser window size
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
body{ background-image: url(../images/bg.jpg); background-repeat: no-repeat; background-color: #000; background-size:contain; } body{ background-image: url(../images/bg.jpg); background-repeat: no-repeat; background-color: #000; background-size:cover; } /* best choice below */ @media screen and (max-width: 1024px) { /* Specific to this particular image */ img.bg { left: 50%; margin-left: -512px; /* 50% */ } }