OGeek|极客世界-中国程序员成长平台

标题: html - 我怎样才能使位置:fixed work on iOS 7? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:17
标题: html - 我怎样才能使位置:fixed work on iOS 7?

我创建了一个测试网页,演示 UIWebView 和 Mobile Safari 上的 position:fixed 问题:

<!DOCTYPE html>
<html style="overflow: hidden; ">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.2, user-scalable=no">
  <title>Test</title>

  <style type="text/css">
    * {
      -webkit-tap-highlight-color: rgba(0,0,0,0);
    }
    body {
      margin: 0px;
      padding: 0px;
    } 
    .fullscreen {
      background: transparent;
      display: block;
      position: absolute;
      top: 0; left: 0;
      width: 100%;
      height: 100%;
    }
    .screen {
      position: fixed;
      left: 0px;
      top: 0px;
      width: 100%;
      height: 100%;
      /*-webkit-box-shadow: inset 0 0 10px #0d1f2b;
      -moz-box-shadow: inset 0 0 10px #0d1f2b;
      -o-box-shadow: inset 0 0 10px #0d1f2b;*/
      box-shadow: inset 0 0 10px #0d1f2b;
    }
  </style>
</head>
<body>
  <div class="screen" id="screen"></div>
  <form><textarea id="code" name="code" class="fullscreen" rows="1">
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
  </textarea></form>
</body>
</html>

重现步骤:

  1. 在 iPad 或 iPhone 上的 Mobile Safari 上打开演示网页。
  2. 点击文本区域以显示键盘。
  3. 向上或向下滚动以查看问题。

嵌入的阴影应该沿着浏览器窗口的边缘,但它不正确地位于页面下方。

enter image description here

如何使 position:fixed 正常工作?



Best Answer-推荐答案


原始问题没有答案,但它是具有相同结果的解决方案。将 body 的样式更改为以下内容:

.body {
  margin: 0px;
  padding: 0px;

  /*-webkit-box-shadow: inset 0 0 10px #0d1f2b;
  -moz-box-shadow: inset 0 0 10px #0d1f2b;
  -o-box-shadow: inset 0 0 10px #0d1f2b;*/
  box-shadow: inset 0 0 10px #0d1f2b;

  min-height: 100%;
}

screen 元素可以被移除。

关于html - 我怎样才能使位置:fixed work on iOS 7?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19179792/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4