html – div内容保证金推送容器

我遇到了一个令我困惑的问题.

我有一个容器,我想将背景应用到浏览器屏幕右上角的位置.里面的div有一个4em的上边距,这是推动容器div.

CSS:

#container {
background: transparent url("../images/house-bg.png") top right no-repeat scroll;
}

#wrapper {
    background: #FFF;
    width: 960px;
    height: 600px;
    margin: 4em auto 0;
    border: 10px solid #C3CF21;
    -moz-border-radius: 20px;
    -webkit-border-radius: 20px;
    border-radius: 20px;
    -moz-Box-shadow: 0 0 25px #444;
    -webkit-Box-shadow: 0 0 25px #444;
    Box-shadow: 0 0 25px #444;
}

HTML:

<div id="container">
        <div id="wrapper">
            <div id="header">

            </div>
            <div id="main">

            </div>
        </div>
        <div id="footer">
            &copy; copyright <?PHP echo date("Y");?> Company,Inc.
        </div>
    </div>

我希望包装器的边距位于容器div内而不是外部.

我尝试了多个显示属性和位置属性无济于事.唯一能解决问题的是插入“& nbsp;”在#wrapper开始之前,必须要对此进行CSS修复.

解决方法

您可以添加overflow:hidden以便“关闭”#container div中的上下文.

在这里,http://jsfiddle.net/kQsPR/尝试删除溢出:隐藏,它将按照您的描述运行.

此行为在此处指定:
http://www.w3.org/TR/CSS2/visuren.html#block-formatting

In a block formatting context,each
Box’s left outer edge touches the left
edge of the containing block (for
right-to-left formatting,right edges
touch). This is true even in the
presence of floats (although a Box’s
line Boxes may shrink due to the
floats),unless the Box establishes a
new block formatting context (in which
case the Box itself may become
narrower due to the floats).

这正是“隐藏”以外的“溢出”能够(建立新的格式化上下文),例如,您也可以通过在#container元素中添加border-top来实现.

相关文章

vue阻止冒泡事件 阻止点击事件的执行 &lt;div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些