Custom element with position absolute

Cheetah

I am trying to contain/put a fin-hypergrid within a web component, but because it's scrollbars are custom divs with position: absolute on them, they are positioned absolute to the window rather that the component itself.

Here is my jsfiddle: https://jsfiddle.net/50kyyfam/

I'm almost certain I need to add a css properties to the :host style to tell the grid to position absolute to the boundary of the data-grid component, but I don't know what it should be?

EDIT: As a side note, if any of the fin-hypergrid are looking, the minified version of core threw an exception when initialising the above jsfiddle. (Chrome 63)

UncaughtTypeError

To position an absolutely positioned element relative to its containing element, position: relative should be declared on that containing element, e.g:

data-grid {
    position: relative;
}

class DataGrid extends HTMLElement {

    constructor() {
      super();
      this.createShadowRoot().innerHTML = `
      	<style>
        	:host {
          	display: block;
          }
          
          div {
          	height: 100%;
          	width: 100%;
          }
        </style>
        <div></div>
      `;
    }

    connectedCallback() {
			const grid = new fin.Hypergrid(this.shadowRoot.querySelector('div'));
      const data = [
        { name: 'Company 1', price: 300 },
        { name: 'Company 2', price: 200 },
        { name: 'Company 3', price: 150 },
        { name: 'Company 4', price: 500 },
        { name: 'Company 5', price: 999 }
      ];
      grid.setData(data);
    }

  }

  customElements.define('data-grid', DataGrid);
data-grid {
    position: relative;
}
<script src="https://fin-hypergrid.github.io/core/2.0.2/build/fin-hypergrid.js"></script>

<data-grid style="width:100px; height: 150px;"></data-grid>

Updated JSFiddle

To expand upon, for the sake of clarity and for the potential benefit of any other possible readers:

  • When declaring an element as an absolutely positioned element (absolute or fixed) you are removing the element from the natural document flow; which simply means the element is no longer interacting with sibling elements in the way relative or static elements do (imagine the element "siting above" the rest of the DOM).
  • By default, an absolutely positioned element's position is "relative" to the window; this means if you offset its position with left or right property values it'll move a distance equal to the property value from the window. You can position an element with a position property value of absolute (not fixed) relative to any containing element if you declare relative positioning to that containing element.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Elm - absolute position of an element

From Dev

Elm - absolute position of an element

From Dev

Position element inside position absolute

From Dev

Fixed position element inside absolute position element

From Dev

Fixed position element inside absolute position element

From Dev

Position absolute in pseudo element of blockquote

From Dev

Position absolute and relative on one element?

From Dev

100% width on position absolute element

From Dev

How to position the element using absolute position?

From Dev

Position relative element in front of absolute element CSS

From Dev

Align position absolute element to the end of the relative element

From Dev

Width of element with (position: absolute) inside element with (position:relative)

From Dev

Position absolute element is the child of the page, instead of the position relative element

From Dev

UL List inline with absolute position element inside it

From Dev

How to use absolute position relative to parent element

From Dev

with bootstrap, adding position absolute changes width of element

From Dev

Catch click event on absolute position element

From Dev

Position element inside absolute parent with respect to grandparent

From Dev

Align element center keeping the position absolute

From Dev

Position element without using absolute positioning

From Dev

Dynamically position absolute element on game map

From Dev

Position element absolute relative to 100% width parent

From Dev

CSS position absolute - next positioned element is body?

From Dev

How to center position:absolute element in a responsive layout

From Dev

floated element clipped by absolute position div

From Dev

How to use absolute position relative to parent element

From Dev

Resize position absolute element width to content with CSS

From Dev

Dynamically position absolute element on game map

From Dev

How to center absolute position element in my case

Related Related

  1. 1

    Elm - absolute position of an element

  2. 2

    Elm - absolute position of an element

  3. 3

    Position element inside position absolute

  4. 4

    Fixed position element inside absolute position element

  5. 5

    Fixed position element inside absolute position element

  6. 6

    Position absolute in pseudo element of blockquote

  7. 7

    Position absolute and relative on one element?

  8. 8

    100% width on position absolute element

  9. 9

    How to position the element using absolute position?

  10. 10

    Position relative element in front of absolute element CSS

  11. 11

    Align position absolute element to the end of the relative element

  12. 12

    Width of element with (position: absolute) inside element with (position:relative)

  13. 13

    Position absolute element is the child of the page, instead of the position relative element

  14. 14

    UL List inline with absolute position element inside it

  15. 15

    How to use absolute position relative to parent element

  16. 16

    with bootstrap, adding position absolute changes width of element

  17. 17

    Catch click event on absolute position element

  18. 18

    Position element inside absolute parent with respect to grandparent

  19. 19

    Align element center keeping the position absolute

  20. 20

    Position element without using absolute positioning

  21. 21

    Dynamically position absolute element on game map

  22. 22

    Position element absolute relative to 100% width parent

  23. 23

    CSS position absolute - next positioned element is body?

  24. 24

    How to center position:absolute element in a responsive layout

  25. 25

    floated element clipped by absolute position div

  26. 26

    How to use absolute position relative to parent element

  27. 27

    Resize position absolute element width to content with CSS

  28. 28

    Dynamically position absolute element on game map

  29. 29

    How to center absolute position element in my case

HotTag

Archive