What version of CRM are you using? The CSS changed from 4.0 to 2011 to 2013/15. I have been able to do this in the past, but it was kludgy and not very well supported.
An alternative might be to create a web resource HTML page that does this, and then put that web resource into the header of the form. I don't have any sample code for this, sorry, but I've seen it done.