Is it possible to set the width of a div to be the same as it’s closest sibling when the width on that div is width: auto;?
In my jsFiddle you will see that I have a red, green and blue div. I want the blue div to adjust to the size of the green div (which is dynamic). So if the green div works out to be 200px then I want the blue div to be 200px.
Originally I thought I would be able to put the blue div inside the green one and set display: inline-block on the child, but this does not work.
So, if the content of the blue div increases then it won’t push the width of the green div out (or the container div). How can this be achieved?
If you are willing to use JavaScript, you can adjust the width whenever the div you want to track changes. Using jQuery, it’s simple:
Here is a fork of your jsFiddle with this code added, plus I added more text to the secondary title to expand it to show that it works.