html - 修复我正在使用 HTML 制作的游戏的背景图像
问题描述
又是我带着另一个新的决赛项目。
我正在尝试使用 HTML 制作游戏,而我现在正在制作主菜单,但我一直坚持下去。
背景图像不合适,我已经搜索并尝试了我在互联网上可以找到的所有解决方案,但它就是不正确。
这是它的样子。如您所见,它不适合。我试图使 bg 图像适合而无需滚动。我使用了 1920x1080 的图像
body {
background-image: url("main menu bg.png");
background-size: contain;
background-repeat: no-repeat;
background-size: 100% 100%;
background-position: center top;
}
<!DOCTYPE html>
<html>
<head>
<link rel = "stylesheet"
type = "text/css"
href = "stylemenu.css" />
<title> Trio of Battles </title>
</head>
<body>
<button button style="background-color: transparent;" onclick="myFunction()"><img src="start button.png"></button>
</body>
</html>
解决方案
通过将 body height 更改为 100vh,您可以确保没有滚动条。并且使用包含,图像将始终适合屏幕。
body {
background: url("main menu bg.png")no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: contain;
overflow: auto;
margin: 0;
height: 100vh;
}
推荐阅读
- java - 递归启用子节点xml groovy
- node.js - Node.js 中的同步 HTTP 请求
- javascript - Html锚标记中的字符串连接
- r - 在 optim() 中:par[1] 中的错误:“闭包”类型的对象不是子集 - 用于带约束的线性回归的 optim()
- c# - 为不同实体生成序列
- react-native - 如何解决模块'App'找不到'react-native'应用程序
- android - Android:如何处理 startActivityForResult 调用的活动异常?
- java - 春季启动时的“为 gson 覆盖托管版本 2.8.1”警告会有多糟糕?怎么可能避免?
- c++ - c ++:如何在Windows上以编程方式检索驱动程序安装日期
- ubuntu - 通过共享 NFS 驱动器在 SLURM 上运行 MPI