【问题标题】:Equal height divs within containing element?包含元素内的高度相等的div?
【发布时间】:2013-03-13 11:24:26
【问题描述】:

这是我的 HTML(或访问luxury-decor.co.uk)

<div class="wrapper">
    <div class="box_left">
        <p>Providing only the highest quality service work, both internal and external, in Reading, London and surrounding areas. We provide a bespoke service for any areas such as boardrooms, offices, showrooms, hotel lobby's, reception areas, bathrooms, wet rooms,
            kitchens and living areas. We specialise in Venetian Marble Plastering, Painting and Decorating, and both Wall & Floor Tiling. Our decorators are meticulous in what they do and we always strive to adhere to our customers needs. So whatever your project
            is, get in touch with us via email or telephone to discuss your requirements.
        </p>
    </div>
    <!--#box_left-->
    <div id="gallery_container1">
        <script type="text/javascript">
            jQuery.flashgallery('color_chart/gallery.swf', 'color_chart/config.xml', {
                width: '100%',
                background: '#000000'
            });
        </script>
    </div>
    <!--#gallery_container1-->
</div>
<!--#wrapper-->

现在,您可以看到,当这样设置时,右侧的图片库太大了。是否有可能使“包装器”内的 div 具有相同的高度?我确实遇到过这个http://www.cssnewbie.com/equalheights-jquery-plugin/#.UUBcyhw0xnM,但我对 jQuery 不太熟悉,无法让它工作。有什么想法吗?

【问题讨论】:

    标签: javascript jquery containers parent-child equal-heights


    【解决方案1】:

    只需使用 CSS,

      div#wrapper > div{height:200px} 'assuming you want 200px height for all div within wrapper
    

    如果不回复,我希望这样做:)

    【讨论】:

    • 这可行,但我不想为包装器的高度设置值。我只希望 #gallery_container1 反映 .box_left 的高度
    • 那你可以试试 JavaScript 或者 jQuery-- $("#gallery_container1").height() = $(".box_left").height();
    • 我应该把这段代码放在哪里? &而不是那样,我可以不将 flash 对象放入 jquery 中,以便对象大小而不是 div 发生变化吗?
    • 我想也一样,flash对象,嵌入的时候需要指定大小!! :) 所以也一样,把上面的代码放在 标签中。如果页面需要时间,则正文标签>>onload>> 使用此行调用函数。它的 Jquery 将与 javascript 一起使用。 :)
    【解决方案2】:

    在 CSS 中:

    #wrapper { height: 400px; } //or whatever you like
    
    #wrapper.box_left, #gallery_container1 { height: 100% }
    

    【讨论】:

      【解决方案3】:

      确定包装器的类/名称,我不知道 flashgalley 方法,所以我无法帮助您,只需查找它用作包装器的 div 的类/名称,查看 html,然后找到最大高度并将它们全部设置为:

      var wrappers = $('div.wrapper');
      var maxHeight = 0;
      for(var i in wrappers){
          if (maxHeight < wrappers[i].height()){
              maxHeight = wrappers[i].height();
          }
      }
      $('div.wrapper').height(maxHeight);
      

      这将复制您链接到的插件的功能

      【讨论】:

      • 我将如何整合它?在外部 .js 中?我真的跟不上我的js
      • 你可以在 中使用它,如果所有 div 都具有相同的名称,则可以在 js 文件中使用,如果所有 div 都具有相同的名称,则将 div.wrapper 替换为 div[name=thename]同一个类用 div.theclass 替换它
      猜你喜欢
      • 1970-01-01
      • 2014-10-19
      • 1970-01-01
      • 2013-11-20
      • 2014-01-13
      • 1970-01-01
      • 1970-01-01
      • 2017-09-14
      • 1970-01-01
      相关资源
      最近更新 更多