Media Queries Based on Element Width with MutationObserver
You have probably faced a situation before where you really wished CSS media queries were based on elements’ width rather than the entire viewport. This article explores a JavaScript approach to add different attributes to an element depending on its width using resize event and MutationObserver.
You have probably faced a situation before where you really wished CSS media queries were based on elements’ width rather than the entire viewport. In this article we will explore a JavaScript approach to add different attributes to an element depending on its width using resize event and MutationObserver. You can then use these attributes to style the element differently in your CSS.
An excerpt from Media Queries Based on Element Width with MutationObserver