https://codepen.io/ypppp/full/xxaZGxr
html
1<html> 2 <head> 3 <meta charset="utf-8"> 4 <style> 5 .main { 6 width: 500px; 7 height: 500px; 8 overflow-x: scroll; 9 position: relative; 10 border: 1px solid black; 11 } 12 .contents { 13 width: 1500px; 14 height: 50px; 15 } 16 .button { 17 position: absolute; 18 bottom: 10px; 19 right: 10px; 20 height: 30px; 21 width: 50px; 22 background-color: red; 23 user-select: none; 24 cursor: pointer; 25 } 26 </style> 27 </head> 28 <body> 29 <div class="main"> 30 <div class="contents"></div> 31 <div class="button">ボタン</div> 32 </div> 33 <script> 34 document.getElementsByClassName("contents")[0].innerText = "コンテンツ".repeat(100); 35 </script> 36 </body> 37</html>
main要素の中のボタンは、絶対位置でmain要素の右下に配置しています。
しかし、右にスクロールすると、絶対位置で配置したボタンが何故か左に動いてしまいます。
これをスクロールしてもしなくても常に右下に配置するにはどうすればよいのでしょうか?できればcss内で完結させたいです。

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/02/20 10:49