positioning Flashcards

1
Q

what are the positioning options?

A

absolute, relative, static (default), fixed, sticky

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does adding “position: static” to an element accomplish?

A

Elements are positioned static by default. Position static does nothing but simply allow an element to sit in the normal flow of the page. It is not affected by top, left, bottom, and right properties.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does adding “position: relative” to an element accomplish.

A

A relative positioned element can be positioned relative to where it would have normally appeared in the document. This means that if it has parent elements, the positioning of this element will occur relative to where the parent elements caused this element to be positioned. e.g. if the parent element has a padding of 10px and you add a property of “left: 10px” to the relative positioned child element, the element will get placed 10px from the left of the 10px padding i.e. 20px from the left border of the parent element.

Notes:
Relative-positioned elements can overlap sibling elements within a container.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does adding “position: absolute” to an element accomplish?

A

Absolute positioned elements are positioned relative to it’s first positioned ancestor i.e. the ancestor that is not positioned as static. This may seem similar to relative positioning however the key difference is that it’s positioned relative to the positioned ancestor and not itself. This means that properties that would affect a relative positioned element (e.g. padding) won’t affect an absolute positioned element.

Gotchas:
- absolute positioning can be hard to maintain in the world of responsive screens. If static values are set on an absolute positioned element, the scaling of the positioned ancestor can lead to unintended and unexpected positioning of the absolute positioned element. If absolute positioning is needed for a responsive layout take care to use relative units for the positioning attributes (e.g. %, rem, etc)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does adding “position: fixed” to an element accomplish?

A

This means an element is positioned relative to the viewport. This can be useful if a user wants a component to stay “fixed” to the screen as a user scrolls down the page.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does adding “position: sticky” to an element accomplish?

A

A sticky-positioned element is positioned depending on the scroll position. It will be positioned relative until the scroll reaches a certain position and then it will be positioned as fixed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly