css - 如何包含 float 在容器 div 之外的 div

标签 css html overflow

我正在做一个“主题”设计,但我又遇到了问题。我在容器 div 中有一个 float 的 div(向左),它超出了它的边界。它是动态的,因此设置 height: 属性是不够的。现在我知道是 float: left;那是造成它的原因,但我怎样才能尝试适应它呢?我尝试将外部 div 设置为 display: table;这行得通,但随后它没有将另一个 div 设置为 float 的 div 来填充宽度。

enter image description here

html:

    <div class="reply-wrapper">
    <div class="reply-box">
        <div class="reply-header">
            <span id="post-id">#1</span>
            <span id="post-date">Today, 12:08</span>
        </div>
        <div class="reply-main">
            <div class="user-info">
                <div class="username-wrap">
                    <span id="username">Jakes625</span>
                    <!-- img online or not? -->
                </div>
                <span id="usertitle">Admin</span>
                <ul class="user-stats">
                    <li>Posts: 99</li>
                    <li>Rep: 99</li>
                    <li>Likes: 99</li>
                </ul>
            </div>
            <div class="reply-data">
                <div class="reply-post">
                    <h2>Post Title</h2>
                    <p>
                        So this is some text that goes in a post.
                    </p>
                </div>
                <div class="reply-signature">
                    This is an example signature.
                </div>
            </div>
        </div>
        <div class="reply-footer">
            <span class="reply-button">Reply With Quote</span>
        </div>
    </div>
</div>

CSS:

    .reply-wrapper{
    background-color: #DDD;
    border-radius: 6px;
    padding: 6px;
    font: normal 12px arial, helvetica, sans-serif;
    color: #333;
}
.reply-box{
    border: 1px solid #c6c6c6;
    border-radius: 4px;
    margin-bottom: 30px;
}
.reply-box:last-child{
    margin-bottom: 0;
}
.reply-header{
    background-color: #474747;
    border-bottom: 1px solid #c6c6c6;
    border-radius: 4px 4px 0 0;
    padding: 4px;
    color: #FFF;
}
.reply-header #post-id{
    float: right;
}
.reply-main{
    background-color: #ebebeb;
}
.reply-main .user-info{
    width: 180px;
    float: left;
    background-color: #e5e5e5;
    border-right: 1px solid #c6c6c6;
    padding: 10px;
}
.reply-main .reply-data{
    margin-left: 200px;
    margin-right: 0px;
}
.user-info .username-wrap,.user-info #usertitle{
    text-align: center;
    display: block;
    text-align: center;
}
.username-wrap #username{
    font-size: 11pt;
}
.user-stats{
    margin: 0;
    padding: 0;
    list-style-type: none;
    margin: 10px 0 10px 0;
}
.user-stats li{
    background: #f2f2f2 none;
    color: #3e3e3e;
    border: 1px solid #c6c6c6;
    margin-bottom: 3px;
    padding: 4px;
    line-height: 20px;
}
.reply-post{
    padding: 10px;
}
.reply-post h2{
    margin: 0;
    padding: 0;
    border-bottom: 1px solid black;
}
.reply-signature{
    border-top: 1px solid #c6c6c6;
    padding: 10px;
}
.reply-footer{
    padding: 4px;
    height: 15px;
    background-color: #d8d8d8;
    border-top: 1px solid #c6c6c6;
}
.reply-footer .reply-button{
    float: right;
}

页面来源:http://jakes625.toomanylols.com/thread.html

最佳答案

改变:

.reply-main .user-info{
    width: 180px;
    float: left;
    background-color: #e5e5e5;
    border-right: 1px solid #c6c6c6;
    padding: 10px;
}
.reply-main .reply-data{
    margin-left: 200px;
    margin-right: 0px;
}

到:

.reply-main .user-info{
    width: 180px;
    display: inline-block;
    background-color: #e5e5e5;
    border-right: 1px solid #c6c6c6;
    padding: 10px;
}
.reply-main .reply-data{
    margin-left: 200px;
    margin-right: 0px;
    display: inline-block;
}

这将并排显示两个 div,同时拉伸(stretch)外部 div 以使其适合。如果你想要的是相反的(使 div 的高度等于外部 div 的高度,不管它的内容如何)那么另一个发布的答案就是你正在寻找的东西

jsfiddle here

关于css - 如何包含 float 在容器 div 之外的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19471981/

相关文章:

c - float 溢出但不是当 C 中的 printf 参数时?

当虚拟键盘可见时,页面中心的 CSS 元素被推高

html - 根据父级高度动态对齐伪元素

javascript - 按 Angular 加权平均值排序

html - 无法使用 flexbox align-items 和 justify-content 使按钮居中

javascript - 溢出滚动停止在选定的点

javascript - jquery body css overflow-x 不起作用

html - Internet Explorer 中的 SVG Scaling Giant,适用于 Chome(AngularJS)

javascript - 多个DIV的翻转动画

css - 我们能否使某些图像无响应,即在 Bootstrap 响应站点中调整浏览器窗口大小没有影响?我找不到任何东西?