I have a page with many different objects of different widths. I am not setting the width of the div that the objects are within as I want it to be able to expand to include whatever items are within it. But I do want the div to have a minimum width. Is it possible to do this?
You can simply use the CSS display property with the value inline-block to make a <div> not larger than its contents (i.e. only expand to as wide as its contents).
The min-width CSS property sets the minimum width of an element. It prevents the used value of the width property from becoming smaller than the value specified for min-width .
Using Min Width and Max WidthIf min-width value is larger than max-width , then the min-width value will be taken as the width for the element. Consider the following example. The initial width value is 100px , and adding on that, there is min-width and max-width values.
It is very possible. Just use CSS min-width
. The MDN page has details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With