Any way to conditionally change CSS styles in a custom record summary template?

Any way to conditionally change CSS styles in a custom record summary template?

Hello,

I have a record summary that includes fields that come from a related form. Each record in the first form may or may not have a related record from the second form.
Now our client wants us to hide the fields from the related form if the first record doesn't have a related record.

I tried using a formula field that returns "display: none;" or "display: block;" to insert CSS styles into the record summary, but when I view the record summary, the CSS is removed.

Is there any way to use field values for CSS or inline styles? I would like to be able to edit the HTML of the record summary without having the HTML I write removed or altered.