The easiest, cheapest (free) and less visible way is to use an empty soda bottle, preferably the ones with straight sides. One makes a slit length-wise so it can unrolled, and cuts off the neck. Then i can be taped to the top of your filter. The other end is fitted into the tank, sealing the gap. By making it wider or narrower, you can accommodate different filters or cover more or less of the gap. (Picture below. In this case I am using it to modify flow, not to seal a gap).
This is the same DIY that is used to reduce the forward rush of the outflow of a filter (if one has sensitive small fish or plants), without modifying the actual strength of the output. But one can cut it shorter so that it closes the gap(s) without entering the actual water, thus not changing the flow.
I tape mine with wide clear (packing) tape, and has lasted for years.
When servicing the filter, I turn it off, flip up the baffle (soda thing) onto the lid, and remove the lid with it attached. One needs to tape it only once in a lifetime. One can do a similar procedure to seal other gaps that are not in front of the filter.
Good luck.
View attachment 1444201