Simplify CSS selector
Handle case where sidebar empty, fixes #5537