android - 我的网站背景无法在移动设备上正确呈现
问题描述
它在桌面和 web 开发模式( firefox )上完美显示,但在真实移动设备上,背景图像无法正确显示。
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="css/css_index.css">
<title>This is Shivansh's Blog</title>
</head>
<body>
<div class="parent">
<div class="parent_hello_box">
<span class="parent_hello_text">Hello !</span>
</div>
<div class = "footer">
<ul class = "nav_menu">
<li class = "nav_item">
<a href="https://www.google.com">About</a>
</li>
<li class = "nav_item">
<a href="https://www.google.com">Work</a>
</li>
<li class = "nav_item">
<a href="https://www.google.com">Movies</a>
</li>
<li class = "nav_item">
<a href="https://www.google.com">Books</a>
</li>
<li class = "nav_item">
<a href="https://www.google.com">Travels</a>
</li>
<li class = "nav_item">
<a href="https://www.google.com">Photos</a>
</li>
<li class = "nav_item">
<a href="https://www.google.com">Spirit</a>
</li>
</ul>
</div>
</div>
</body>
</html>
这是我的CSS:
/**, html {
margin:0;
padding:0;
}*/
@font-face {
font-family: rage;
src: url("../fonts/rage_gtavc.ttf");
}
@font-face {
font-family: milkshake;
src: url("../fonts/milkshake/milkshake.ttf");
}
@media only screen and (min-width: 144px) {
.parent_hello_text {
font-size: 64px;
}
}
@media only screen and (min-width: 320px) {
.parent_hello_text {
font-size: 96px;
}
}
@media only screen and (min-width: 480px) {
.parent_hello_text {
font-size: 128px;
}
}
@media only screen and (min-width: 720px) {
.parent_hello_text {
font-size: 144px;
}
}
@media only screen and (min-width: 1024px) {
.parent_hello_text {
font-size: 196px;
}
}
body {
background-image: url("../bg/196339.jpg");
/*width: 100%;*/
height: 100%;
background-size: cover;
-webkit-background-size: cover;
background-attachment: fixed;
background-repeat: no-repeat;
background-position: center;
}
.parent_hello_box {
transition: 0.5 all;
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 100%;
text-align: center;
}
.parent_hello_text {
color: white;
text-shadow: 2px 3px #FABF84;
font-family: milkshake;
}
.footer {
position: absolute;
bottom: 1.2vh;
width: 100%;
text-align: center;
}
.footer a {
text-decoration: none;
font-family: rage;
font-size: 36px;
color: #FDFDFD;
text-shadow: 2px 2px #FC53A7;
/*text-shadow: 2px 2px #F449B9;*/
}
.footer a:hover {
text-decoration: underline;
}
.nav_menu {
z-index: 9;
display: inline-block;
}
.nav_item {
margin-left: 20px;
margin-right: 20px;
display: inline-block;
transform: rotate(-8deg);
}
解决方案
问题在于位置属性,您将绝对设置为子元素,但没有固定相对位置。通过这个https://www.w3schools.com/cssref/pr_class_position.asp
推荐阅读
- css - 如何将背景图像的中心点向下移动?
- javascript - 如何将模型中的数据获取到 JavaScript 函数中?
- python - 使用 R 和 Python 的不同多项式回归系数
- resharper - 重新锐化,
并悬停智能感知 - java - 如果收到广播,将调用应用程序类 OnCreate
- javascript - Javascript将文本字段限制为数字和小数?
- java - Embedded Jetty:如何在源代码中设置 JMX 端口
- amazon-dynamodb - 使用值列表查询 DynamoDB GSI
- javascript - 反应 ref 以通过呈现为 this.props.children 的子级
- java-8 - 缓存 Java 8 流