I want to create a div that able to expand the width when user input the text
I tried to set width:100%; max-width:600px; min-width:300px;
But some how this div just stay at 600px, is that any way to keep the width stay at 300px and able to expand to 600px base on the length of the content?
Really appreciate if you can help. Thanks
Try setting display: inline-block on the element and see if that helps you out any. This should make it only expand as far as its content while still paying attention to the minimum and maximum widths. You may have to add a breaker <br /> after to make the rest of your content adapts to it being inline.
CSS tip: To reset a min-height or min-width declaration, set it to "0", not "auto". For max-height/width, the initial value is "none". Also see nimbupani.com/safe-css-defau… Just used this to solve resetting width on #mobileFirst breakpoints!
The min-width property in CSS is used to set the minimum width of a specified element. The min-width property always overrides the width property whether followed before or after width in your declaration.
max-width overrides width , but min-width overrides max-width .
Setting the div to display: inline-block
allows it to shift width depending on the contents.
Otherwise, as a block level element, the div will take up 100% of it's containing element (or however wide you set max-width
).
Here's a an example:
http://cssdesk.com/Bwp8E
Try:
width: auto;
max-width: 600px;
min-width: 300px;
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