Responsive Web Design

Media Queries Based on Element Width with MutationObserver

Media Queries Element 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.