【问题标题】:float left resizing images 100% whit parent向左浮动调整图像大小 100% 白色父级
【发布时间】:2013-09-24 18:45:44
【问题描述】:

我正在开发网站的移动版本。 在某个页面上,您在左侧有三张图片,当您单击它时,您会在右侧看到大图片。

当您调整窗口大小时,左侧的三个图像的分辨率会变大。我想要完成的是右边的图像应该与左边的三个图像的高度相同。

因此,当您调整窗口大小时,蓝色和绿色 div 的高度应该相同。

您可以在here或以下找到我的代码

<div id="outer">
    <div id="inner1">
        <ul>
            <li>
                <img style="-webkit-user-select: none" src="http://placekitten.com/50/50" />
            </li>
            <li>
                 <img style="-webkit-user-select: none" src="http://placekitten.com/50/50" />
            </li>
            <li>
                  <img style="-webkit-user-select: none" src="http://placekitten.com/50/50" />
            </li>
        </ul>
    </div>
    <div id="inner2">
        <img style="-webkit-user-select: none" src="http://placekitten.com/50/50" />
    </div>
    <div style="clear: both;"></div>
</div>

样式

#outer{
    border: 1px solid red;
    width: 100%;
}

#inner1{
    border: 1px solid blue;
    width: 30%;
    float: left;
    margin-right: 20px;
}

#inner1 img{
    width: 100%;
}

#inner2{
    border: 1px solid green;
    width: 100%;
    height: 100%
}

ul{
    list-style-type: none;  
}

谢谢!!

【问题讨论】:

    标签: css image resize height floating


    【解决方案1】:

    这是Working Fiddle 测试于: IE10、IE9、IE8、IE7、FF、Chrome、Safari

    仅供参考:我还修复了您在 inner1 div 图像中遇到的 100% 宽度问题。 (这是由 ul-li 默认边距引起的)

    HTML:(删除了你的clear:both; div)

    <div id="outer">
        <div id="inner1">
            <ul>
                <li>
                    <img src="http://placekitten.com/50/50" />
                </li>
                <li>
                    <img src="http://placekitten.com/50/50" />
                </li>
                <li>
                    <img src="http://placekitten.com/50/50" />
                </li>
            </ul>
        </div>
        <div id="inner2">
            <img src="http://placekitten.com/50/50" />
        </div>
    </div>
    

    CSS:

    * {
        padding: 0;
        margin: 0;
    }
    #outer {
        border: 1px solid red;
        position: relative; /* new */
    }
    #inner1 {
        width: 30%;
        border: 1px solid blue;
        display: inline-block; /*instead of the floating*/
    }
    ul {
        list-style-type: none;
    }
    #inner1 img {
        width: 100%;
    }
    #inner2 {
        border: 1px solid green;
        width: 60%;
        position: absolute;
        top: 0; /* stretchs from the beginning of the parent .. */
        bottom: 0; /* ..to the end. */
        right: 0; /*instead of float:right */
    }
    

    【讨论】:

      猜你喜欢
      • 2020-09-25
      • 1970-01-01
      • 1970-01-01
      • 2019-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-12
      相关资源
      最近更新 更多