css float 和边框问题

标签 css css-float

我得到了这个 CSS:

.post-user {
    background:black;
    color:white;
    width:auto;
    float:left;
}
.img-side {
     border-style:solid;border-width:medium;width:75px;margin-bottom:2px;
}
.top-head {
    background:cyan;
    width:100%;
    height:20px;
    display:block;
}
.main-box {
    border-style:solid;
    border-width:1px;
    display:block;
    height:auto;
}

html 看起来是这样的:

<div class="main-box">
    <div>
        <div class="top-head"><span>At top</span>
        </div>
        <div class="side">
            <div class="img-side">
                <img src="http://st2.gsmarena.com/vv/pics/htc/htc-snap-1.jpg" width="75px" height="75px" />
            </div>
        <div class="post-user">User name</div>
        </div>
    </div>
</div>

demo

但是 div post-user 超出了边界。

我该如何解决? (P.S.:有点类似论坛的布局)

最佳答案

http://jsfiddle.net/PGFTz/5/我在 post-user 之后添加了一个清晰的修复程序,使其能够保留在框内。

关于css float 和边框问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7287744/

相关文章:

css - 奇怪的 float div 行为

jquery - 使多个 div 相互 float

HTML、CSS Box模型问题

css - 我怎样才能停止向左浮动?

html - 小屏幕显示自己div之外的内容

css - 图像未使用 z-index 显示在标题上方?

html - 我怎样才能模仿表格的流体单元格宽度但仍然允许换行?

css - 如何创建网格/平铺 View ?

CSS变换比例在Safari中不起作用

javascript - 如何用javascript覆盖CSS?