Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

min-width doesn't work

Tags:

html

css

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

like image 423
wayne Avatar asked May 20 '11 03:05

wayne


People also ask

Why my min width is not working?

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.

How do I reset the min width?

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!

Does width override min width?

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.

Does Min width override max width?

max-width overrides width , but min-width overrides max-width .


2 Answers

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

like image 198
Nick Tomlin Avatar answered Nov 15 '22 11:11

Nick Tomlin


Try:

width: auto;
max-width: 600px;
min-width: 300px;
like image 40
Ryan Olds Avatar answered Nov 15 '22 12:11

Ryan Olds