简体   繁体   English

CSS div高度未拉伸

[英]CSS div height not stretching

I'm programming a website and on a page I have dynamic content. 我正在为网站编程,在页面上有动态内容。 To be specific I want to display some content in a div each. 具体来说,我想在div中分别显示一些内容。 And the main div wont stretch upon this content. 而且主要的div不会扩展此内容。

#main{
    position:relative;
    background-image:url(images/main_middle.png);
    background-repeat:repeat-y; 
    width:850px;
    min-height:450px;
}
.intrebari{
    position:relative;
    width:400px;
    min-height:150px;
    padding:20px;
}

while($row=mysql_fetch_array($rezultat)){
    echo '<div class="intrebari">
                 <div id="upleft"></div>
         <div id="upright"></div>
         <div id="downleft"></div>
         <div id="downright"></div>
        '.$_SESSION['username'].' a intrebat:<br />
        '.$row['question'].'
         </div>';
}

What am I doing wrong? 我究竟做错了什么?

The internal div has to be cleared so the outer should know the height of the inner div you may use a class 必须清除内部div,以便外部可以知道内部div的高度,您可以使用一个类

.clear{
  clear:both;
}

and introduce it after your inner div inside outer div main 并在您的内部div内部外部div main之后介绍它

echo '<div class="intrebari">
                 <div id="upleft"></div>
         <div id="upright"></div>
         <div id="downleft"></div>
         <div id="downright"></div>
        '.$_SESSION['username'].' a intrebat:<br />
        '.$row['question'].'
         </div><div class="clear"></div>';

this will help you 这会帮助你

If you have given float to intrebari, you need to give float left or right to main div to get the main wrap the inner content 如果将float赋予intrebari,则需要将float赋予main div左右,以获取主包装的内部内容

.intrebari{
    position:relative;
    width:100%
    min-height:150px;
    padding:20px;
}

if you want to have the content of the div.intrebari stretch horizontaly make the width of value to 100% 如果要水平放置div.intrebari的内容,请将值的宽度设置为100%

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

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