I have a dynamic container. It contains a paragraph, and some other elements.
<div id="container" style="border: 2px solid black; position: absolute; display: flex; flex-direction: column; width: auto">
<p>This is a long description. It is very long. It has many sentences. There are details contained within.</p>
<p>Short p</p>
<input type="number" style="width:200px" />
<button style="width: 50px">OK</button>
</div>
Note that the container becomes widened severely by the long paragraph. This is not desired. I would like the container to be sized based on the children not including the paragraph. So I'd like to have the container width constrained by the default numeric input field width, or the button, whichever is wider. Note if the first paragraph tag is removed then it looks the way I want, as that 2nd short p
does not exceed the width of the input.
I'm actually a web developer by trade and have been doing this for 10 years. This is one of the few remaining snags with CSS now that we already seemingly have a world of nice things with flex, grid, etc. available to us today. But it's these chicken-egg type problems that continue to frustrate, and I can't even find a way to properly google solutions to this problem.
What is the approach here? Do I try to hack the paragraph to take the width of a sibling? Why does it not work if I set width: 100%
on the offending non-wrapping paragraph?