Two inline-block elements next to each other.
.e{border:1px #ccc solid}
.e:hover{border-color:#555}
What I’d like is to reduce the 1px+1px border between them to a shared 1px border.
To illustrate.
---------
| | |
---------
Select first element.
+++++-----
+ + |
+++++-----
Select second element.
-----+++++
| + +
-----+++++
It’s simple to reduce the 2px border to 1px by setting either border-right or border-left to 0, but how to keep the 1px shared border when either element is selected?
Without JavaScript.
You could give them a -1px left margin to get their borders overlapping and then undo that margin on the first one. Then adjust the
z-indexon hover (and don’t forgetposition: relativeto make thez-indexwork). Something like this:Demo: http://jsfiddle.net/ambiguous/XTzqx/
You might need to play with the
:first-childa bit depending on how your HTML is structured; a couple other options if:first-childor another pseudo-class won’t work:<div>withpadding-left: 1pxto kludge around themargin-left: -1px.margin-left: 0.