javascript - Stretch to fit the entire screen without keeping aspect ratio and without scrollbars
问题描述
I am trying to stretch an image in an < img > tag to fit the entire screen independent from aspect ratio. For example, I want it to fit the whole screen both on a 16:9 and a 21:9 screen. I tried the following css as well as size: 100% 100%;
Neither of them worked, there are scrollbars on the sides of my browser window.
I want to achieve this: http://nemesisvisuals.com.
As you can see the background image (I am using an < img > tag on purpose so I want the same results but with the < img > tag) stretches to fit the screen no matter what.
<!DOCTYPE html>
<html>
<head>
<style>
img{
height: 100vh;
width: 100vw;
}
</style>
</head>
<body>
<img src="img.jpg">
</body>
</html>
解决方案
You're almost there:
* {
margin: 0;
padding: 0
}
img {
display: block;
height: 100vh;
width: 100vw;
}
<img src="https://picsum.photos/1280/720">
推荐阅读
- angular - 量角器等待角度应用稳定
- node.js - 异步回调中的摩卡测试
- android - kotlin 绑定类引用和泛型
- javascript - 如何在 javascript 中使用 fetch() 读取 JSON 文件?
- c++ - STXXL 在使用非常快的 SSD 时表现不佳
- linux - 无法在 shell 脚本中打印公共 ip
- swift - 从字符串中删除标点符号,Swift 中的破折号除外
- reactjs - 如果 api 响应需要更长的时间,则在 UI 中显示超时错误
- phaser-framework - fire from a weapon of project motion using phaser 2.5.0
- android - 在模拟器下运行金鱼内核的分段错误