2015-10-02 18 views
8

私は400pxの高さを言うとdivを持っています。内容はずっと長いので、divはスクロール(y軸)することができます。 divの右側には、そのdiv内に固定位置を持つためにいくつかのボタンが必要ですスクロールdiv内の固定位置

どうすればいいですか? jQuery、CSS、何でも - 私は気にしません。

私はfixToを試してみましたが、これはうまくいかないようです - そして "use position:fixed、left/right - just margin"というCSSソリューション。それは正常に動作しますが、ページ自体がスクロールすると、ボタンもスクロールします。彼らは常にdiv内で固定しておく必要があります。

例コード:

<div class="container" style="width: 960px; height: 400px; position: relative;"> 
    <div class="buttons needToBeFixed"></div> 
    <div class="aLotOfContent" style="width: 2000px;"></div> 
</div> 
+0

あなたは、問題のコード例を持っていない、私は問題を理解すると思いますが、視覚的には、それが簡単に – nykc

+0

はいを​​解決するためになるだろう - ちょうどそれを追加しました。 –

+0

[親に対して固定要素を配置することはできますか?](http://stackoverflow.com/questions/5209814/can-i-position-an-element-fixed-relative-to-parent) –

答えて

0

あなたのdivの内側にあるものに応じて、固定位置にdiv要素の外にオブジェクトを追加することができますか?あなたのdivがその内部のデータに依存している場合、javascriptはコンテンツ全体を集約して、全体に依存する必要なアクションを実行することができます。

+0

私は確信していません、私は理解しています。はい、divは内部のデータに依存しています.JS自身を理解することはできませんので、解決策やjQueryプラグインへのリンクを探しています。 –

+0

実例を教えてもらえますか? – mh00h

+0

いくつかのHTMLマークアップを追加しました。 .containerが本体で、position:fixedが.buttonで使用されているとします。それが私が望むものです。 –

0

ボタンを下に置き、margin-top:-400pxを使用して解決しました。

<div style="position: relative"> 
    <div class="container" style="height: 400px;"></div> 
    <div class="buttons" style="margin-top: -400px; position: absolute; right: 0;"></div> 
</div> 

と思われます。誰かがより良い解決策を持っていれば、彼らはもちろん歓迎です。すべてのあなたの答えをありがとう。

+0

解決策のサンプルを提供できますか? –

0

HTMLマークアップを変更し、相対的な位置のラッパー要素を使用できます。次に、position: absolute;を使用して、この親に対する要素のpostionningを行うことができます。

body { 
 
    width: 1500px; 
 
    height: 1500px; 
 
} 
 
#wrapper { 
 
    position: relative; 
 
    width: 350px; 
 
    overflow: hidden; 
 
} 
 
#container { 
 
    height: 350px; 
 
    overflow-y: scroll; 
 
    border: solid #000 1px; 
 
} 
 
.sticky { 
 
    position: absolute; 
 
} 
 
.right { 
 
    right: 0; 
 
} 
 
.bottom { 
 
    bottom: 0; 
 
}
<div id="wrapper"> 
 
    <input type="button" value="Sticky button" class="sticky top" /> 
 
    <input type="button" value="Sticky button" class="sticky bottom left" /> 
 
    <input type="button" value="Sticky button" class="sticky right" /> 
 
    <input type="button" value="Sticky button" class="sticky bottom right" /> 
 
    <div id="container"> 
 
    <div class="content">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It 
 
     has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop 
 
     publishing software like Aldus PageMaker including versions of Lorem Ipsum. 
 
     <br />Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
 
     It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with 
 
     desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div> 
 
    </div> 
 
</div>

関連する問題