html - 使图像相对于其父容器具有静态位置?

标签 html css image static scroll

我正在制作一个图像预览容器,可以在页面底部找到这个 URL:

http://cowperthwaite.dev.mybusinessadmin.com/location/51447

在底部,您可以看到缩略图有一个滚动条,因为父容器的高度无法容纳。这很好,并且正在按预期工作。

我遇到的问题是我需要左侧的大图像始终保持在 View 中,即使向下滚动也是如此。换句话说,我需要它相对于其父 div 保持静态 - 始终在黄色框中 - 而缩略图有一个滚动区域。

我已经尝试了各种position:_______ 变体,但都无济于事,而且我觉得我在这里遗漏了一些更高的概念。我也不确定我想要完成的事情是否有可能实现。

有人介意提供一些见解吗?提前致谢

编辑:derp,没有提供我的代码...

HTML:

<div class="pictureBoxContainer">
    <div class="pictureBox">
        <div class="pBoxLeftColumn">
            <?php
                echo "<div class='pBoxLargeImageContainer'>";
                echo "<img src='$pictureLinks[0]' id='largeImage' alt='Primary Image' class='pBoxLargeImage'>";
                echo "</div>";
            ?>
        </div>
        <div class="pBoxRightColumn">
            <?php
            foreach ($pictureLinks as $picture) 
            {
                echo "<div class='pBoxSmallImageContainer'>";
                echo "<img src='$picture' alt='Thumbnail' class='pBoxSmallImage'>";
                echo "</div>";
            }
            ?>
        </div>
    </div>
</div>

CSS:

.pictureBoxContainer {
    padding: 12px;
    clear:left;
    clear:right;
    width: 100%;
    background-color: #F7D961;
    border-radius: 12px;
    max-height: 350px;
}

.pictureBox {
    background-color: #FFF;
    border-radius: 12px;
    width: 97%;
    overflow: auto;
    padding: 12px;
    max-height: 300px;
}

.pBoxLeftColumn {
    display: block;
    float: left;
    min-width: 49.99%;
    max-width: 49.99%;
    overflow: auto;
}

.pBoxRightColumn {
    display: block;
    float: right;
    min-width: 49.99%;
    max-width: 49.99%;
    overflow: auto;
}

.pBoxSmallImageContainer {
    height: 103px;
    width: 145px;
    float: left;
    padding: 3px;
    margin: 3px;
    background-color: #F7D961;
    border-radius: 2px;
    position: relative;
}

.pBoxSmallImage {
    max-height: 95px;
    max-width: 138px;
    margin: auto;
    display: block;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
}

.pBoxLargeImageContainer {
    width: 100%;

}

.pBoxLargeImage {
    border-radius: 6px;
    min-width: 450px;
    max-height: 300px;
    position: static;
}

最佳答案

position: relative 添加到 pictureBoxContainer div 并将以下样式添加到 pBoxLeftColumn div:

.pBoxLeftColumn {
    display: block;
    left: 25px;
    max-width: 49.99%;
    min-width: 49.99%;
    position: absolute;
    top: 25px;
}

关于html - 使图像相对于其父容器具有静态位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16612935/

相关文章:

html - 为什么最小高度不增加以适应增加的内容

css - Rails - 在 Rails 4 应用程序的供应商 css 中使用供应商字体 - Assets 管道

html - 为什么图像在 MAC 上不占据浏览器的整个宽度?

python - Pygame 游戏中角色被卡住

html - 为什么我在 pythonanywhere 中的 CSS 需要一天时间才能加载?

php - Google reCAPTCHA - 不断获取 `incorrect-captcha-sol`

css - 单击时调用另一个元素上的指令

php - joomla 2.5 模块中的图像插入字段

javascript - 从值为 "xyz"的属性中获取 HTML 标记

html - 底部的页脚,仅当向下滚动超过主体元素/超过窗口高度的 100% 时才可见?