compute bg margin