What is the most elegant way to check whether an element is in the normal flow using jQuery?
According to the CSS3 specification,
A box belongs to the flow if:
The used value of its ‘display’ is ‘block’, ‘list-item’, ‘table’ or template.
The used value of its ‘float’ is ‘none’.
The used value of its ‘position’ is ‘static’ or ‘relative’.
It is either a child of the flow root or a child of a box that belong to the flow.
Should I just check for all these conditions, or is there a better way?
I think another “in flow” requirement is that
overflowis set tovisible.From the CSS2 spec:
Based on the requirements you quoted and the
overflowrequirement, this is one way to do it with jquery:See this jsFiddle for test cases.
I’m not sure if it would be better to use
window.getComputedStyle()or not.The function is checking to see if
elmis inctxRoot‘s flow or block formatting context (as it was previously called, I think). IfctxRootis not supplied, it will check against thebodyelement. This does not check to make surectxRootis in flow. So, with this HTMLThe test cases are: