我正在编写一个即将推出的页面,它在桌面模式下运行良好!但在手机中,图像的一些艺术作品被隐藏了,
你可能会注意到,在移动 View 中,它隐藏了艺术品的某些部分
但它在桌面模式下效果很好:
这是我的完整片段:
<!DOCTYPE html>
<html>
<head>
<title>HOME: </title>
</head>
<style>
body, html {
height: 100%;
margin: 0;
}
.bgimg {
background-image: url('bg12.png');
height: 100%;
max-width: 100%;
background-position: center;
background-size: cover;
position: relative;
color: black;
font-family: KhmerUI;
src: url(KhmerUI.ttf);
font-size: 25px;
}
.topleft {
position: absolute;
top: 0;
left: 16px;
}
.bottomright {
position: absolute;
top: 0;
right: 30px;
}
.middle {
position: absolute;
top: 50%;
left: 70%;
transform: translate(-50%, -50%);
text-align: center;
}
hr {
margin: auto;
width: 40%;
}
</style>
<body>
<div class="bgimg">
<div class="topleft">
<img src="loDgo-2.png" alt="logo" style="width:150px;height:120px;">
</div>
<div class="middle">
<h1>COMING SOON</h1>
<hr>
<p>STAY TUNED</p>
</div>
<div class="bottomright">
<p>Powered By</p>
<img src="cropD-3.png" style="width:150px;height:50px;">
<div></div>
</div>
</div>
</body>
</html>
这是我的背景图片:
谁能帮我修复移动 View ,我需要图像的艺术作品看起来像我看到的桌面模式。艺术品藏不住
最佳答案
一种解决方案是将样式更新为:
.bgimg {
background-image: url('bg12.png');
height: 100%;
max-width: 100%;
background-position: center;
background-size: contain;
background-repeat: no-repeat;
position: relative;
color: black;
font-family: KhmerUI;
src: url(KhmerUI.ttf);
font-size: 25px;
}
为了进一步自定义图像的位置,您使用媒体查询在 background-position
上尝试不同的选项
在此处查看更多信息: CSS background-size cover and background-position
这里: https://www.w3schools.com/cssref/pr_background-position.asp
关于html - 使背景图像响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58004247/