Need a CSS solution to stay top left with page scrolling (not position:fixed)

Airman

I need to open/close a div container that will always appear at the top left corner no matter where I am on a page that has page scrolling. Position fixed would be acceptable in a desktop environment but in a mobile environment I need the user to be able to pull up or move down the div container so they can get to other input fields. If I use position absolute the div container could appear out of view if you are scrolled down at the bottom of the page.

Example problem using fixed... The mobile device popup keyboard will cover the lower input field. If you change position to absolute then you can see the out of view issue. https://jsfiddle.net/r71vb73u/15/

 #workarea {
 width: 160px;
 padding: 5px;
 height: 400px;
 position: fixed;
 background: #cccccc;
}

.input1 {
 height: 90%;
}

.input2 {
 height: 10%;
}

.blah {
 float: left;
}

.buttons {
 float: right;
}

.filler {
 clear: both;
 height: 800px;
}

function workarea(action) {
  if (action == 'open') {
    document.getElementById('workarea').style.display = '';
  } else {
    document.getElementById('workarea').style.display = 'none';
  }
}

<body>
  <div id="workarea">
    <div class="input1">
      <input type="text" value="hello">
    </div>
    <div class="input2">
      <input type="text" value="world">
    </div>
  </div>
  <div class="blah">blah blah ...</div>
  <div class="buttons">
    <input type="button" value="Open" onMouseDown="workarea('open');">
    <input type="button" value="Close" onMouseDown="workarea('close');">
  </div>
  <div class="filler"></div>
  <div class="blah">blah blah ...</div>
  <div class="buttons">
    <input type="button" value="Open" onMouseDown="workarea('open');">
    <input type="button" value="Close" onMouseDown="workarea('close');">
  </div>
</body>
Airman

Looks like I can add the following to the javascript action open:

document.getElementById('workarea').style.top = document.body.scrollTop + 10 + 'px';

This places the workarea at current top using position absolute.

https://jsfiddle.net/r71vb73u/28/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

CSS Positioning: Fixed Left or Top when scrolling

From Dev

Prevent page scrolling to top upon adding fixed position

From Dev

Table header to stay fixed at the top when scrolling

From Dev

HTML/CSS Float Left and Top/Bottom without position absolute/fixed

From Dev

Make tvOS tableview row stay in fixed position while scrolling

From Dev

HTML CSS DIV Layout with Top, Left, and Right DIVs fixed with a scrolling Center DIV

From Dev

HTML CSS DIV Layout with Top, Left, and Right DIVs fixed with a scrolling Center DIV

From Dev

Ghost dom element navbar fixed top does not stay in position

From Dev

JQuery Position:Fixed 'NAVBAR' by scrolling the page

From Dev

JQuery Position:Fixed 'NAVBAR' by scrolling the page

From Dev

Make DIVs in Accordion/Collapsible stay fixed at top and bottom of page

From Dev

Position fixed acting like position relative ( scrolling with page )

From Dev

CSS Position fixed not fixing header to top

From Dev

debug lag of calculate margin top for Position fixed sidebar scrolling to bottom

From Dev

Header Div position fixed on top of page but on load show a div on top of it

From Dev

Position center not top left corner of an image in css

From Dev

How to position a div left to another div and top fixed to body?

From Dev

Revealing A Div Fixed to Page Top After Scrolling 95 Pixels

From Dev

Parts of page are invisible when scrolling on Safari 7 with position:fixed elements

From Dev

Position absolute but with fixed scrolling

From Dev

DIV Slide to the left and stay on top

From Dev

CSS Fixed position menu - scrolling issue when resizing the browser

From Dev

CSS - White space around top and left of page

From Dev

HTML -- cannot get header to stay fixed in scrolling

From Dev

CSS rotate and position to bottom left of page

From Dev

Why does adding a rect then setting its left and top cause a selectable 'ghost' rect to stay in the old position?

From Dev

Fixed Page Scrolling

From Dev

two Position Fixed on top

From Dev

Bootstrap 3 Fixed Top Navbar 'Flickering' On Mobile Scrolling using jQuery One-Page Scrolling Effect

Related Related

  1. 1

    CSS Positioning: Fixed Left or Top when scrolling

  2. 2

    Prevent page scrolling to top upon adding fixed position

  3. 3

    Table header to stay fixed at the top when scrolling

  4. 4

    HTML/CSS Float Left and Top/Bottom without position absolute/fixed

  5. 5

    Make tvOS tableview row stay in fixed position while scrolling

  6. 6

    HTML CSS DIV Layout with Top, Left, and Right DIVs fixed with a scrolling Center DIV

  7. 7

    HTML CSS DIV Layout with Top, Left, and Right DIVs fixed with a scrolling Center DIV

  8. 8

    Ghost dom element navbar fixed top does not stay in position

  9. 9

    JQuery Position:Fixed 'NAVBAR' by scrolling the page

  10. 10

    JQuery Position:Fixed 'NAVBAR' by scrolling the page

  11. 11

    Make DIVs in Accordion/Collapsible stay fixed at top and bottom of page

  12. 12

    Position fixed acting like position relative ( scrolling with page )

  13. 13

    CSS Position fixed not fixing header to top

  14. 14

    debug lag of calculate margin top for Position fixed sidebar scrolling to bottom

  15. 15

    Header Div position fixed on top of page but on load show a div on top of it

  16. 16

    Position center not top left corner of an image in css

  17. 17

    How to position a div left to another div and top fixed to body?

  18. 18

    Revealing A Div Fixed to Page Top After Scrolling 95 Pixels

  19. 19

    Parts of page are invisible when scrolling on Safari 7 with position:fixed elements

  20. 20

    Position absolute but with fixed scrolling

  21. 21

    DIV Slide to the left and stay on top

  22. 22

    CSS Fixed position menu - scrolling issue when resizing the browser

  23. 23

    CSS - White space around top and left of page

  24. 24

    HTML -- cannot get header to stay fixed in scrolling

  25. 25

    CSS rotate and position to bottom left of page

  26. 26

    Why does adding a rect then setting its left and top cause a selectable 'ghost' rect to stay in the old position?

  27. 27

    Fixed Page Scrolling

  28. 28

    two Position Fixed on top

  29. 29

    Bootstrap 3 Fixed Top Navbar 'Flickering' On Mobile Scrolling using jQuery One-Page Scrolling Effect

HotTag

Archive