Given the following DOM structure...
<div id="outer-container">
<div class="side-panel"><div width="200px"/></div>
<div id="content"><!-- some content --></div>
<div class="side-panel"><div width="100px"/></div>
</div>
With the following CSS rules...
#outer-container {
display: 'flex';
align-items: 'stretch';
width: '100vw';
height: '100vh';
}
.side-panel {
flex-shrink: 0;
}
#content {
display: 'flex';
flex-direction: 'column';
align-items: 'stretch';
flexGrow: 1;
}
How can I observe mutations to the width/height of #content
?
This is typically done by observing mutations in the style
attribute, and checking the bounds of the element (or some other variation) when the style has changed. However, being a flex container & child, I notice that when I inspect the width/height of the element, they are not defined.
Changes to the size of #content
does not produce events from my MutationObserver (which uses the following config: {attributes: true, attributeFilter: ['style']}
)
My use case here is to turn the side panels into drawers when the #content
width decreases below some defined threshold. I am working with React
, however this seems to be a native html/js problem.
Help greatly appreciated!
PS: I tried setting flex-basis
on #content
to my chosen threshold, but this didn't help. I wonder if I should define a width
instead of flex-basis
.. however I'm unsure if this will produce undesired flex behaviour.