【问题标题】:html fixed widths and dynamic layouthtml 固定宽度和动态布局
【发布时间】:2015-03-10 04:23:52
【问题描述】:

我有以下代码。 div_2是否可以在父div没有宽度的情况下动态扩展父div?

<div>
    <div id="div_1"></div>
    <div id="div_2"></div>
    <div id="div_3"></div>
</div>

#div_1, #div_2, #div_3{
float:left;
}
#div_1{
width:300px;
}
#div_3{
width:350px;
}

【问题讨论】:

    标签: html css width fixed


    【解决方案1】:

    我不确定我理解你的意思,但这可能是你想要的吗?

        #div_1, #div_2, #div_3{
    float:left; height: 400px;
    }
    #div_1{
        width:100px;
        background: red;
    }
    #div_3{
        width:150px;
        background: blue;
    }
    #parent{
        border: 4px solid #000;
        float:left;
    }
    

    http://fiddle.jshell.net/ndqkg2hq/

    【讨论】:

      【解决方案2】:

      是的。这是可能的。由于您要给子 div 一些浮动,因此您需要向父 div 提供溢出。它可能被溢出隐藏。它应该工作。如果宽度还是有问题,在父div的宽度上加上auto。

      .parentdiv{overflow:hidden;width:auto;}
      

      【讨论】:

        【解决方案3】:

        是的,您可以在父 div 下方尝试使用 css,或者您也可以将 .clearfix 类添加到父 div 中

        body > div{overflow:hidden;width:auto;}
        

        或

        <div class="clearfix">
        <div id="div_1"></div>
        <div id="div_2"></div>
        <div id="div_3"></div>
        </div>
        

        .clearfix 类的css

        .clearfix:after {
         visibility: hidden;
         display: block;
         font-size: 0;
         content: " ";
         clear: both;
         height: 0;
         }
        .clearfix { display: inline-block; }
        /* start commented backslash hack \*/
        * html .clearfix { height: 1%; }
        .clearfix { display: block; }
        /* close commented backslash hack */
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-07-23
          • 1970-01-01
          • 1970-01-01
          • 2014-12-22
          • 1970-01-01
          • 1970-01-01
          • 2012-01-23
          相关资源
          最近更新 更多