5 Modal/Dialog web development problems you should know

Jan 16, 2020(5 years ago)-
Fuxing's Picture
Fuxing Loh

In a perfect world, this is what you want:

img.png

1. Nested Positions

img_1.png

<div style="positon: relative">
  <modal-dialog style="position: absolute" />
</div>

Having multiple conflicting nested positions. Using position: fixed might fix your problem but in some older browser or some edge scenario, position: fixed still works unreliably when the element is nested inside other position values.

2. Overlapping z-index

img_2.png

Overlapping z-indices can be an annoying problem when trying to render your modal above element with higher z-index implementation. However, you can’t just avoid using z-index entirely, some design requirement still requires you to use z-index to overlay elements above.

For my projects, I have a z-index schema that I reference.

.index-9,
.index-overlay,
.nuxt-progress {
  z-index: 1000000000 !important;
}
 
.index-1,
.index-content {
  z-index: 10;
}
 
.index--1 {
  z-index: -1;
}

3. Cascading Parent CSS

img_3.png

.parent {
  font-size: 24px;
}

If you nest your Modal inside a parent element with overarching CSS rules, it might conflict with your modal CSS rules.

4. Scrolling Issues

img_4.png

Your body scroll when your modal is above. You tried locking the scroll bar, but your modal has overflowing content.

Solution? Use this body-scroll-lock library.

5. iOS Safari 100vh

img_5.png

What you see when designing. What you see when testing. What the user actually sees. What you actually want.

Conclusion

Use a modal library.

Also, you can check out this microsite that I created to illustrate those 5 issues.