【问题标题】:Force image div container to stretch inside custom image box layout强制图像 div 容器在自定义图像框布局内拉伸
【发布时间】:2015-10-14 07:27:01
【问题描述】:

我开发了自定义图像框 html 控件,其中包含图像区域以及位于主图像底部、顶部、左侧或右侧的小图像缩略图集合。 问题是主图像 div 容器没有拉伸以填充主框架 div 中的剩余区域。

这是我的代码

.wvIBoxFrameDiv {
    width: 300px;
    height: 300px;
    background: red;
 }

.wvIBoxMainImageDiv {
    background: green;
}

.wvIBoxThumbContainerDiv{
    background: black;
    overflow: hidden; 
    white-space: nowrap;
}

.wvIBoxThumbImagesContainerDiv{
    background: blue; 
    display: inline-block; 
}

.wvIBoxThumbNavigationDiv{
    background: purple;
    display: inline-block;
    height: 30px;
    width: 30px;
}

.wvIBoxThumbImageDiv{
    background: orange;  
    display: inline-block;
    height: 40px;
    width: 40px;
}
<div class="wvIBoxFrameDiv">
    <div class="wvIBoxMainImageDiv">
    </div>
    <div class="wvIBoxThumbContainerDiv">
        <div class="wvIBoxThumbNavigationDiv"></div>
        <div class="wvIBoxThumbImagesContainerDiv">
            <div class="wvIBoxThumbImageDiv"></div>
            <div class="wvIBoxThumbImageDiv"></div>
            <div class="wvIBoxThumbImageDiv"></div>
            <div class="wvIBoxThumbImageDiv"></div>
            <div class="wvIBoxThumbImageDiv"></div>
            <div class="wvIBoxThumbImageDiv"></div>
        </div>
        <div class="wvIBoxThumbNavigationDiv"></div>
    </div>
</div>

这里我需要将缩略图 div 容器(黑色背景)放置在主(红色)框架 div 的底部,而主图像 div(绿色背景)应该拉伸以填充剩余区域。

我做错了什么?

【问题讨论】:

    标签: javascript html css


    【解决方案1】:

    heightwidth 作为100%.wvIBoxMainImageDiv

    .wvIBoxFrameDiv {
        width: 300px;
        height: 300px;
        background: red;
     }
    
    .wvIBoxMainImageDiv {
        background: green;
        height:100%; /*this here*/
        width:100%; /*and here*/
    }
    
    .wvIBoxThumbContainerDiv{
        background: black;
        overflow: hidden; 
        white-space: nowrap;
    }
    
    .wvIBoxThumbImagesContainerDiv{
        background: blue; 
        display: inline-block; 
    }
    
    .wvIBoxThumbNavigationDiv{
        background: purple;
        display: inline-block;
        height: 30px;
        width: 30px;
    }
    
    .wvIBoxThumbImageDiv{
        background: orange;  
        display: inline-block;
        height: 40px;
        width: 40px;
    }
    <div class="wvIBoxFrameDiv">
        <div class="wvIBoxMainImageDiv">
        </div>
        <div class="wvIBoxThumbContainerDiv">
            <div class="wvIBoxThumbNavigationDiv"></div>
            <div class="wvIBoxThumbImagesContainerDiv">
                <div class="wvIBoxThumbImageDiv"></div>
                <div class="wvIBoxThumbImageDiv"></div>
                <div class="wvIBoxThumbImageDiv"></div>
                <div class="wvIBoxThumbImageDiv"></div>
                <div class="wvIBoxThumbImageDiv"></div>
                <div class="wvIBoxThumbImageDiv"></div>
            </div>
            <div class="wvIBoxThumbNavigationDiv"></div>
        </div>
    </div>

    【讨论】:

    • 任何时候..快乐编码..:)
    • 嗯...它似乎有一种奇怪的行为:高度为 100% 的图像容器填充了外部框架 div 内的所有空间(300px)。所以底部缩略图 div 移出外框。我该如何解决?
    • 您可以将其减少一些 % 或尝试将 display:inline-block 分配给 main div 的孩子
    • 嗯...我看不到您的演示图像。看来我将不得不使用js手动设置大小。好吧,我想知道为什么这样一个自然的任务没有可接受的解决方案。我只希望底部容器具有自然高度(由其内容确定),而上部图像容器填充其余的全局空间。这很奇怪。
    【解决方案2】:

    你也可以使用 flex,(使用自动前缀):

    <div class="fullGallery">
      <div class="mainImage">
      </div>
      <div class="bottomImages">
        <div class="navigationButton">
        </div>
        <div class="imageContainer">
          <div class="oneImage"></div>
          <div class="oneImage"></div>
          <div class="oneImage"></div>
        </div>
        <div class="navigationButton">
        </div>
      </div>
    </div>
    
    
    .fullGallery {
      width: 300px;
      height: 300px;
      background-color: red;
      display: flex;
      flex-direction: column;
    }
    .mainImage {
      width: 100%;
      flex: 1;
      background-color: yellow;
    }
    .bottomImages {
      width: 100%;
      height: 70px;
      background-color: green;
      display: flex;
    }
    .navigationButton {
      width: 40px;
      height: 100%;
      background-color: pink;
    }
    .imageContainer {
      flex: 1;
      display: flex;
      justify-content: space-around;
    }
    
    .oneImage {
      background-color: blue;
      width: 26%;
    }
    

    http://codepen.io/anon/pen/JYrdQJ

    我更喜欢它

    【讨论】:

    • 好吧,在我发现某些移动设备不支持 flex 之前,它实际上与 flex 完美搭配。所以现在我尝试将几十个 html 和 css 从 flex 重新开发为其他东西
    • 嗯...我的意思是,caniuse.com/#search=flex 带有自动前缀应该没问题,世界上几乎 95% 的人都支持它,但是如果你专注于一种公众,那么...... . 祝你好运,这是一种痛苦…… :(
    • 是的,我看到了 caniuse 结果,但是我的 iphone safari 和 nokia chrome 看起来就像他们从未听说过 abour flex。这很奇怪,但我似乎别无选择。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-20
    • 1970-01-01
    • 2013-10-28
    • 1970-01-01
    • 2020-07-26
    相关资源
    最近更新 更多