2016-04-22 4 views
5

状況:リンク

次単純化されたHTMLの例を考えると

  • はフッターを入れページの最後までスクロールしたときコンテンツの後ろに、それボトムスティッキー
  • ますフッタはコンテンツ
  • 後ろから解明しなければなりません0

は、私がこれを行うことができたが、私が持っているときhtmlbodyの両方が、それはhiddenにフッターにこれらのリンクはクリックできませんoverflow-xプロパティの設定しました。状況に

更新:

は、私はそれが2に#contentためのzインデックスを設定するために、1〜footerためのリンクがクリック可能にすることが可能だということを知っているが、それは違うからmultizoom.jsと干渉するページの一部であり、私の興味ではありません。

質問:

フッター内にあるリンクの両方htmlbodyoverflow-xの設定をどうしますか?そして、なぜの両方とも要素がこのプロパティを設定する必要がありますか? (overflow-xのうちの1つだけを省略するとリンクがクリック可能になります)

実際に私にとっては、古くなったスタイリングの試行で残ったもので、すでに削除されているため、元のプロジェクトにoverflow-xを設定するのはもう問題ありません。しかし、なぜこのような奇妙な行動があるのか​​不思議です。

例:

/* This statement prevents the links in the footer 
 
* from being clickable */ 
 
html, body { 
 
    overflow-x: hidden; 
 
} 
 
/* necessary statements to put footer behind content and 
 
* make it bottom sticky behind content */ 
 
#content { 
 
    /* opaque bg color to block out footer*/ 
 
    background: lightgrey; 
 
    /* border bottom to see where content ends */ 
 
    border-bottom: 1px solid black; 
 
    /* arbitrary height as content placeholder to provoke scrolling */ 
 
    height: 1500px; 
 
    /* use margin to stretch the page in order for 
 
    * footer to become visible at the end of scrolling */ 
 
    margin-bottom: 120px; 
 
} 
 
footer { 
 
    /* bg color to distinguish footer from content */ 
 
    background: grey; 
 
    /* make footer 120px high, centered */ 
 
    padding: 50px; 
 
    line-height: 20px; 
 
    text-align: center; 
 
    /* put footer one layer behind content so that content scrolls 
 
    * before footer while footer itself is fixed at the bottom */ 
 
    z-index: -1; 
 
    position: fixed; 
 
    bottom: 0; 
 
    /* use all the width possible */ 
 
    width: 100%; 
 
} 
 
body { 
 
    /* make page use the whole panel */ 
 
    margin: 0; 
 
}
<html> 
 
<body> 
 
    <div id="content"> 
 
     Here is the content, scroll down until end of page 
 
    </div> 
 
    <footer> 
 
     <a href="#">Here is the footer link (not clickable at the moment)</a> 
 
    </footer> 
 
</body> 
 
</html>

+1

'#content'を' z-index:2; 'とフッタ' z-index:1; 'で相対的に設定すると、すべてが動作します。 bodyのように 'z-index:-1; 'に問題があります。 – Huelfe

+0

私はそれがz-indexs 2対1で動作することを知っていますが(質問を更新します)、マルチズームスクリプト(これはまったく別の問題です)を妨害します。 – xmoex

+0

@xmoexだから '#content'はZ-インデックス?それとも、 'z-index:-1;'を持つ 'footer'ですか? – Green

答えて

1

私はそれについてのマージンの崩壊を見ることができます。 #contentmargin-bottom: 120pxです。下部に空白が入ります。overflow: hidden;は、本体の高さが#contentブロックになるように新しい書式設定コンテキストを作成します。 z-index: -1bodyの後ろにfooterをプッシュします。リンクをクリックすることはできません。あなたがoverflowプロパティを削除するときには、クリック可能になるリンク後#contentmargin-bottomのためと#footerbody外となり、より

しかし、bodyは低い高さを持つことになります。

また、ビューポートのoverflowプロパティは親から外れた固定要素をクリップしないため、#footerは表示され、アクティブなままです。

1

フッター内にあるリンクを行うにはhtmlと体の両方にオーバーフロー-Xを設定していますか?そして、なぜ両方の要素がこのプロパティを設定する必要がありますか? (それらのうちの1つだけがoverflow-xを省略すると、リンクがクリック可能になります)

実際に私にとっては、古いプロジェクトからのオーバーフロー-xを設定するのはもう問題ありません。すでに削除されています。しかし、なぜこのような奇妙な行動があるのか​​不思議です。

it will work when you remove style from htmlと言ったように。

なぜ人々はhtmlのスタイルを使用しますか?

今のところ私は少なくとも3つのケースが発生しました。人々のスタイルはhtmlです。

  1. 彼らは が彼らの祖先から値を継承するもののためのグローバルプロパティの値を設定したい

  2. ブラウザにスクロールバーを強制的に表示させたいとき。

    html, body { 
        min-height: 100.1%; 
    } 
    
  3. ページをテーブルから外したいとき。

私たちは、それが通常の属性(W3 on htmlを)かかりDOM要素であるため、htmlのスタイルを、私、そして私の知る限り、他の多くの人々を知っているように、あなたがしたい場合を除き、強く、それを使用しないように提案することができますそれでいくつかのクールなトリックを行います。スタイリングhtmlは、ブラウザの動作のために望ましくない動作につながる可能性があります。 bodyhtmlの唯一の子ではありません。 headもあります。あなたのページの目に見える部分のスタイルを設定するには、bodyがあります(なぜ、目に見えない部分を最初のスタイルにしますか?)。

1

問題は、フッターに負のZ-インデックスがあり、ボディには何も設定されていない(デフォルトで0になっていますか?) overflow-x:hiddenを本文のcss文に追加すると、フッターで本体が拡張されます(理由はt1m0nの回答を参照してください)。

身体に低いz-インデックスを追加し、相対的に位置付けすると、Chrome、IE、Firefox、およびEdgeで問題が解決されます。

/* This statement prevents the links in the footer 
 
* from being clickable */ 
 
html, body { 
 
    overflow-x: hidden; 
 
} 
 
body { 
 
    position: relative; 
 
    z-index: -2; 
 
} 
 
/* necessary statements to put footer behind content and 
 
* make it bottom sticky behind content */ 
 
#content { 
 
    /* opaque bg color to block out footer*/ 
 
    background: lightgrey; 
 
    /* border bottom to see where content ends */ 
 
    border-bottom: 1px solid black; 
 
    /* arbitrary height as content placeholder to provoke scrolling */ 
 
    height: 1500px; 
 
    /* use margin to stretch the page in order for 
 
    * footer to become visible at the end of scrolling */ 
 
    margin-bottom: 120px; 
 
} 
 
footer { 
 
    /* bg color to distinguish footer from content */ 
 
    background: grey; 
 
    /* make footer 120px high, centered */ 
 
    padding: 50px; 
 
    line-height: 20px; 
 
    text-align: center; 
 
    /* put footer one layer behind content so that content scrolls 
 
    * before footer while footer itself is fixed at the bottom */ 
 
    z-index: -1; 
 
    position: fixed; 
 
    bottom: 0; 
 
    /* use all the width possible */ 
 
    width: 100%; 
 
} 
 
body { 
 
    /* make page use the whole panel */ 
 
    margin: 0; 
 
}
<html> 
 
<body> 
 
    <div id="content"> 
 
     Here is the content, scroll down until end of page 
 
    </div> 
 
    <footer> 
 
     <a href="#">Here is the footer link (IS CLICKABLE NOW!!)</a> 
 
    </footer> 
 
</body> 
 
</html>

-1

body { 
    position: relative; 
    z-index: -2; 
} 

は、私は、CSSにこれらの変更で問題を修正:

#content { 
    ... 
    z-index: 1; 
    position: relative; 
} 

footer { 
    ... 
    z-index: 0; 
} 

説明

のためz-index: -1を設定の場合は、bodyの直後に配置されています。

我々はbody ABOVEそれをしたいので、私たちはそのz-index: 0を設定(またはそれを完全に削除します)

これは、我々はまた、コンテンツを調達する必要があるので、私たちはそのz-index: 1

しかし設定意味 - をフッタので、固定されている場合は、適切な位置が設定されていないものの上に表示されるので、認識された動作を維持するためにcontentposition: relativeを設定する必要があります。

+0

質問はoverflow-xの役割に関するものでした:htmlに設定された隠しと体。このプロパティが設定されていないソリューションは、フッターのZ-インデックスが-1に設定されていても完璧に機能します。 – xmoex

+0

他には何も変更していないので、 'overflow'の設定はそのままです –