While I was blockwise segregating elements of a webpage and drawing borders around those blocks, I encountered an issue where the height
turned out to be 0
when the display
was set to flex
. How can I retrieve the height in such scenarios? I experimented with various methods but they all yielded 0
ul.offsetHeight // yields 0
ul.clientHeight // yields 0
ul.getBoundingClientRect() // also gives me 0
window.getComputedStyle(ul).height // shows 100%
//Even this method returns 0
var range = document.createRange()
range.selectNodeContents(ul)
range.getBoundingClientRect()
UPDATE
Turns out, the issue had nothing to do with the flex
property. The height displayed as 0
simply because the element was not visible on the screen at that moment. I don't wish to delete the question since some people have already devoted their time to it.