4 ms·
I usually make modal position:fixed and use JavaScript to position them in the center or wherever. Same for drop-down menu’s when you click a button.
by devmunchies 4y ago
I usually make modal position:fixed and use JavaScript to position them in the center or wherever. Same for drop-down menu’s when you click a button.
- rockwotj 4y agoHow does position:fixed help with the z-index? Also doesn't this mean you have to listen for scroll events this way and update the XY coordinates for things like dropdowns?
- Izkata 4y ago"position: fixed" removes the element from the layout and positions it relative to the window. You can scroll the page any which way and the element will stay where it is on the screen, making it a good choice to handle X/Y positioning of the modal.
- rockwotj 4y agoI asked how it helps with z-indexes not XY? Also drop downs are "attached" to some element in the UI, and you probably want those menus to scroll with the page
- kijin 4y ago"position: fixed" puts an element in a new stacking context, freeing it from the z-index of its parents.
- Izkata 4y agoThe person you were responding to said they use "position: fixed" so they don't have to worry about z-indexes, and I was explaining why that works. See sibling reply for the more technical explanation.