How to make a DIV that increases in size every time you increase content?

Asked

Viewed 14,256 times

-1

I am doing a course work, I need to do a DIV that increases in size according to the content I add. Can anyone help me?

Would it be right if in css I put like this:

height: ;

?

Aside from the value.

  • 3

    As far as I know, the div already does it automatically.

  • width: 100%; in the css of your div.

3 answers

1

Depends, the div will increase the width or Height?

You can use this for width:

min-width: 100px;
min-width: 500px;

Or for height:

min-height: 100px;
max-height: 500px;

you set a minimum limit for this div and a maximum limit, because when you put content inside the div it will be increased to a certain limit.

1

All the div's have this behavior as default. They will adjust as needed.

What you can do, is set the minimum and maximum size, as Romario Pires commented. This will ensure you a better control of layout, without "messing up" your website.

Any other css that you define, will replace this standard behavior of div. Look at my example: http://jsfiddle.net/pz231z3L/2/

Type any text you want in textarea and observe how the div will adapt to your text. Without the need for any definition. The only thing it possesses is precisely the limit of max-width and max-height, to ensure that she does not overshoot that space and mess up the layout of the site.

Now an important remark, whether your div is not with this behavior, probably there is some property/class that is overwriting this behavior. So I recommend that you improve your question and add the specific case you want to solve.

-2

you must use the properties below

height: auto;

width: auto;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.