Can media queries resize based on a div element instead of the screen?

前端 未结 11 1672
[愿得一人]
[愿得一人] 2020-11-22 04:17

I would like to use media queries to resize elements based on the size of a div element they are in. I cannot use the screen size as the div is jus

11条回答
  •  不思量自难忘°
    2020-11-22 04:49

    You can use the ResizeObserver API. It's still in it's early days so it's not supported by all browsers yet (but there several polyfills that can help you with that).

    Basically this API allow you to attach an event listener to the resize of a DOM element.

    Demo 1 - Demo 2

提交回复
热议问题