简体   繁体   English

如何使用CSS使用其内容扩展div?

[英]How can I make a div expand with its contents using css?

I have a bunch of nested div's on this page. 我在此页面上有一堆嵌套的div。 Each of them can only take content equivalent to their sizes, any more content that is added overflows into the next div. 他们每个人只能接受与其大小相等的内容,添加的任何内容都会溢出到下一个div中。 I would like to make #heading expand as i add more content in to it. 我想在增加更多内容的同时使#heading扩展。 Can this be done using CSS?. 可以使用CSS完成吗?

<div id="heading"> 
     <form action="addplayer.php"method ="post" enctype="multipart/form-data">
         <img src="css/images/pid.jpg" alt="" /><br/> <input type="text" name="playerid" class="textbox"/><br/>
         <img src="css/images/name.jpg" alt="" /><br/> <input type="text" name="name" class="textbox"/><br/>
         <img src="css/images/age.jpg" alt="" /><br/> <input type="text" name="age" class="textbox"/><br/>
         <img src="css/images/position.jpg" alt="" /><br/> <input type="text" name="position" class="textbox"/><br/>
         <img src="css/images/nt.jpg" alt="" /><br/> <input type="text" name="nationality" class="textbox"/><br/>
         <img src="css/images/photo.jpg" alt="" /><br/> <input type="file" name="image" class="textbox"/>
     <input type="submit"  value="Upload"/>
     <form/>    
</div>

If you don't define width and/or height, the div element grows along with its content. 如果您未定义宽度和/或高度,则div元素会随其内容一起增长。 Unless his content is set to absolute! 除非他的内容设置为绝对值! If the content is set to float, you have to set to the container. 如果内容设置为浮动,则必须设置为容器。

div{overflow: hidden;
    height: auto;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM