There are a few times that I am asked to make something like this.
I used to think I have to do this by CSS, until recently, I ran into two html tags.
Fieldset and Legend which do just the same thing.
Here is it, of course you have to give style to them with CSS
<field> <legend></legend> </field>
Very userful tag.