OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Scrollable resizable div with fixed button

  • Thread starter Thread starter stonar96
  • Start date Start date
S

stonar96

Guest
The following HTML shows a scrollable resizable div with a button and a further content div in it.

Code:
<!DOCTYPE html>
<html>
  <head>
    <style>
      .container {
        width: 100%;
        max-width: 100%;
        height: 150px;
        position: relative;
        overflow: auto;
        resize: both;
        white-space: nowrap;
        background: lightgray;
      }

      .container .fixed {
        position: absolute;
        right: 5px;
        top: 5px;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <button class="fixed">Test</button>
      <div class="content">
        texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttext
      </div>
    </div>
  </body>
</html>

The button should be fixed at the top right corner in the div. This works fine for resizing, however, when I scroll, the button moves too. How can I fix this?
<p>The following HTML shows a scrollable resizable div with a button and a further content div in it.</p>
<pre class="lang-html prettyprint-override"><code><!DOCTYPE html>
<html>
<head>
<style>
.container {
width: 100%;
max-width: 100%;
height: 150px;
position: relative;
overflow: auto;
resize: both;
white-space: nowrap;
background: lightgray;
}

.container .fixed {
position: absolute;
right: 5px;
top: 5px;
}
</style>
</head>
<body>
<div class="container">
<button class="fixed">Test</button>
<div class="content">
texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttext
</div>
</div>
</body>
</html>
</code></pre>
<p>The button should be fixed at the top right corner in the div. This works fine for resizing, however, when I scroll, the button moves too. How can I fix this?</p>
Continue reading...
 

Latest posts

Top