HTML objects growing and pushing others
How could I make it so that given two elements let’s say these boxes:
If I clicked over one, it would grow, and the other would shrink like and vice versa:
How can I do this?
I have seen this sort of done with CSS, using the focus tag and adjusting the width. But I have two problems there, first how could I affect the other element, and second as far as I can tell adjusting width will only stretch them right. I have seen people change the way they float the elements to deal with that, but I don’t want to move them around the page to do this.
Pure CSS - Trigger on click: (example)
Using the checkbox hack in CSS you can effectively toggle the widths of the elements when the checkbox is
:checked. Here is what part of the CSS looks like:
Go to the example for the full CSS.
You might also be interested in the original example I made. It takes a different approach, though it doesn’t fully work.
Pure CSS - Trigger on hover: (example)
Unfortunately, neither the adjacent selector, nor the general sibling selector can select previous elements, therefore it makes this a little difficult. I placed 2 general elements before the main elements in order to somewhat solve this issue.
Since this was tagged as JS/jQuery, here are 2 alternative solutions.