我有一个容器,我想将背景应用到浏览器屏幕右上角的位置.里面的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"> © copyright <?PHP echo date("Y");?> Company,Inc. </div> </div>
我希望包装器的边距位于容器div内而不是外部.
我尝试了多个显示属性和位置属性无济于事.唯一能解决问题的是插入“& nbsp;”在#wrapper开始之前,必须要对此进行CSS修复.
解决方法
在这里,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来实现.
原文地址:https://www.jb51.cc/html/226731.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。