为了彻底,有很多方法可以做到这一点。在设置 img 源的某些情况下,JavaScript 可能更有用。也就是说,在大多数情况下,您会想要使用 CSS。您可以在此处阅读所有 CSS 选项:
https://developer.mozilla.org/en-US/docs/Web/CSS/@media
body {
background: url(https://placehold.it/500x1000);
background-size: cover;
background-position: center center;
}
@media screen and (orientation: landscape) {
body {
background: url(https://placehold.it/1000x2000);
}
}
@media screen and (min-width: 1200px) {
body {
background: url(https://placehold.it/2000x3000);
}
}
<!-- body tag is included by default... -->
<!-- hey StackSnippet warriors(trolls)... key example here of a bad time to use it -->
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句