jquery - 设置 Div 以垂直填充父级

标签 jquery html css

我已经研究了一段时间,但似乎无法弄清楚如何正确设置它。

给定这个 HTML:

<div class="item-container bottom-spacer">
        <div id="my-friends"><div id="2" class="user-profile-card">
        <img src="">

        <div><h3>John</h3></div>
        <h3>Details</h3><br>
        Date: Tuesday, June 24th 2014, 11:47 am<br>
        Val1: 22<br>
        Val2: 28<br>
        <div>
            <h3>Notes</h3><br>
            Just some notes...
        </div>
        <div class="user-profile-li-buttons"><button class="delete-button" onclick="friendsPage.deleteFriend(2)">X</button></div>

</div><div id="4" class="user-profile-card">
        <img src="">

        <div><h3>Mr User One</h3></div>
        <h3>Details</h3><br>
        <div>
            <h3>Notes</h3><br>
            Just some notes...
        </div>
        <div class="user-profile-li-buttons"><button class="delete-button" onclick="friendsPage.deleteFriend(4)">X</button></div>
</div><div id="6" class="user-profile-card">
        <img src="">

        <div><h3>Mr User Two</h3></div>
        <h3>Details</h3><br>
        Date: Tuesday, June 24th 2014, 6:30 pm<br>
        Val1: 31<br>
        Val2: 20<br>
        <div>
            <h3>Notes</h3><br>
            Just some notes...
        </div>
        <div class="user-profile-li-buttons"><button class="delete-button" onclick="friendsPage.deleteFriend(6)">X</button></div>
</div></div>
        <div class="clear-fix"></div>
    </div>

还有一些 CSS:

.item-container {
    padding: 20px;
    border: 0 #fff solid;
    background: #ccc;
    box-sizing: border-box;
    -ms-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    border-radius: 0.3ex;
    -webkit-border-radius: 0.3ex;
    -moz-border-radius: 0.3ex;
    overflow: auto;
    height:100%;
}

#my-friends {
    height: inherit;
}

.user-profile-card {
    overflow: hidden;
    background: #333;
    color: #fff;
    border-radius: 0.3ex;
    -webkit-border-radius: 0.3ex;
    -moz-border-radius: 0.3ex;
    margin: 5px;
    float: left;
    font-size: 0.8em;
    width: 160px;
    padding: 5px;
    height: 100%;
}

我最初认为这是因为我使用 jQuery 动态添加 HTML 内容,但在构建 JsFiddle 之后我似乎也错了。

如何让这些内部 div 正确垂直拉伸(stretch)以填充父 div?

fiddle 在这里:

http://jsfiddle.net/

最佳答案

只需将 display:table 添加到 #myfriends

jsFiddle example

关于jquery - 设置 Div 以垂直填充父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24393748/

相关文章:

iPhone/iPad/触摸屏上的 jQuery 拖动与滑动手势逻辑

javascript - 掌握预加载图像

ios - 跟踪 iOS 设备上的 HTML5 Web App 安装

html - Netbeans IDE 无法启动我的本地主机

jquery - 如何复制 Facebook 图片标记功能?

javascript - 使用 Node.js 实时抓取网页

jquery - 将树展开到特定级别

javascript - 在我的设计 html/css/javascript 中需要帮助

css - 当中间的内容发生变化时,让三个 div 自动调整大小

ios - iOS 8 上的 Ratchet 模态错误