Rearrange element view if some are hidden

Hi, I am trying to create a product page and some of my products have custom feature I can show on a page
I have a custom features (red section on a screenshot) and for some items that do not support that I want to hide this section but when I do it via code I get a gap between green section and yellow one.
Is there any way put yellow section right below green one if red section is hidden?
Thanks in advance

Where is the code? Talking about code, which you do not show → makes no sense.

I was asking any suggestions or samples that people came up with. Right now the code is very straightforward, if condition is met then I just call .hide() method on an element.

and now you gave the answer to your own question, by providing the codepart working on your productpage.

now instead → hide() → use → collapse()