【问题标题】:How can I make position:fixed work on iOS 7?如何使位置:固定在 iOS 7 上工作?
【发布时间】:2013-10-04 11:12:07
【问题描述】:

我创建了一个测试网页,展示了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. 向上或向下滚动以查看问题。

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

如何让position:fixed 正常工作?

【问题讨论】:

    标签: html iphone ios uiwebview mobile-safari


    【解决方案1】:

    原始问题没有答案,但它是具有相同结果的解决方案。将 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 元素可能会被移除。

    【讨论】:

    • 我认为.fullScreen 是文本区域:&lt;textarea id="code" name="code" class="fullscreen" rows="1"&gt;
    • 对不起,我已经根据更正的代码编写了答案。我已经修好了。
    • .fullScreen 在哪里应用于body?我在问题中发布的代码中看不到这一点。
    • 我还添加了一条说明,它不是答案,但它是一个解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-07
    • 2010-12-14
    • 1970-01-01
    • 2015-03-20
    相关资源
    最近更新 更多