2

我在一个 DIV 中的 css 中有三个 DIVS。我还有另外两个 DIVS,当父 div 中的 div 的值扩展时,我想要它们,所以父级应该让他自己也扩展,这不是这样的。

它只是扩展内部 DIVS 而不是父级,这是我的代码:

<div style="background-color:#000; color:#FFFFFF;
width:444px; height: auto;">

    <div align="left" style="margin-top:10px; width:90px;
    height:auto; background-color:#FFF; float:left;
    color:#FF3; margin:5px 5px;">
        Lable:
    </div>

    <div style="margin-top:10px; width:330px;
    height:auto; margin:5px 5px; background-color:#FFF; float:right; color:#FF3; border:solid 1px #000;">
        In here goes the value of the In here goes the value of theIn here goes the value of theIn here goes the value of theIn here goes the value of theIn here goes the value of theIn here goes the vae value of the
    </div>

</div>
4

4 回答 4

2

对父元素使用溢出,因为您的子 div 浮动:

<div style="overflow: hidden; background-color:#000; color:#FFFFFF; width:444px; height: auto;">

或使用代替

float:left; 

儿童

display: inline-block;
于 2013-06-11T06:04:47.833 回答
1

Done. here is jsfiddle link you need to add style

overflow:hidden

to parent div.

于 2013-06-11T06:07:01.553 回答
1

You have to clear the floats. Add this before ending the main div

<div style="clear:both;height:0px; width:0px">&nbsp;</div>

jsfiddle

于 2013-06-11T06:07:20.640 回答
1

尝试这个,

<div style="background-color:#000; color:#FFFFFF;width: auto; height: auto;position: absolute;">

<div align="left" style="margin-top:10px; width:90px;
height:auto; background-color:#FFF; float:left;
color:#FF3; margin:5px 5px;">
    Lable:
</div>

<div style="margin-top:10px; width:330px;
height:auto; margin:5px 5px; background-color:#FFF; float:right; color:#FF3; border:solid 1px #000;">
    In here goes the value of the In here goes the value of theIn here goes the value of theIn here goes the value of theIn here goes the value of theIn here goes the value of theIn here goes the vae value of the
</div>
</div>
于 2013-06-11T06:09:36.240 回答