ホームページ  >  記事  >  ウェブフロントエンド  >  Position:Fixed が古いモバイル ブラウザーで機能しないのはなぜですか?

Position:Fixed が古いモバイル ブラウザーで機能しないのはなぜですか?

Linda Hamilton
Linda Hamiltonオリジナル
2024-10-29 02:35:02643ブラウズ

Why is Position: Fixed Not Working in Older Mobile Browsers?

モバイルブラウザで固定位置が機能しない

問題:

CSS の位​​置を使用して要素の位置を固定する: 修正済み古いバージョンの iOS および Android モバイル ブラウザでは動作しない可能性があります。この要素は、固定位置を無視して、ページとともにスクロールします。

原因:

iOS などの古いブラウザ

5 および Android

解決策:

Use -webkit-backface-visibility: hidden;

<code class="css">.fixed {
  position: fixed;
  top: 0px;
  left: 0px;
  width: 320px;
  height: 50px;
  background: red;
  -webkit-backface-visibility: hidden; /*--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Most Important*/
}</code>

この CSS プロパティは、ブラウザーに要素を 3D 要素として強制的に処理させ、固定位置を有効にします。

<code class="html"><div class="fixed">
  Hi I m Position Fixed
</div>
<div>
  sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
  <br/>sample text
</div></code>
サンプル コード:

このソリューションはテスト済みで、古いバージョンの iOS や Android を含むほとんどのモバイル ブラウザでスムーズに動作します。

以上がPosition:Fixed が古いモバイル ブラウザーで機能しないのはなぜですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。