Monday, August 15, 2016

Appear on hover

Recently I needed a way to have controls for resizing appear on hover using pure CSS. I wanted allow progressive discovery of the feature to collapse the panels but did not want have a clutter of controls. I also wanted that once the user learns about the new feature they can directly access it by moving their mouse there and clicking.

I did it using :nth-child(1), :nth-child(2), and :hover pseudo classes. For the pair on left hand side, the key idea is that, I had to use display:inline-block; on the container span and float: left; style on :nth-child(2)to get around the CSS limitation of not being able to use a following sibling in markup order to affect the style of preceding sibling.

Do you have better suggestions?

No comments: