2014-09-30 134 views
-3

我需要创建以下布局: 有一个容器可容纳站点的所有内容,容器需要在浏览器窗口中居中。该容器具有非固定高度,因为它需要随内容一起扩展。在容器内部会有另一个div来存放实际的页面内容。CSS - 重叠div的定位

然后我的问题,需我重叠的容器div的左边界,因为这将是一个非常特殊的边境特殊股利(不使用任何的CSS边框属性的提示)。

没关系改变与JavaScript中的重叠div的高度(你不需要告诉我如何)。但是我希望只在html和css中完成定位。我将非常感谢所有的建议。

+2

您将获得更快的帮助,如果你发布你想出了到现在为止的代码,该代码的像http://jsfiddle.net网站上的演示 – Arbel 2014-09-30 20:18:38

+0

向我们展示你的代码迄今为止。另外,请解释您的边框有什么特别的地方,它不能被渲染为边框。 – 2014-09-30 20:21:00

+0

Div不是背景吗? – Foxsk8 2014-09-30 20:22:48

回答

0

很无聊,于是决定练,继承人DEMO

<div id="container"> 
    <div id="content"> 
    <p> Hey I am the content</p> 
     <p> Hey I am the content</p> 
      <p> Hey I am the content</p> 
      <p> Hey I am the content</p> 
      <p> Hey I am the content</p> 
      <p> Hey I am the content</p> 
      <p> Hey I am the content</p> 
    </div> 
    <div id="special"> 

    </div> 

</div> 

#container {background: orange; 
width:50%; 
margin:0 auto; 
padding: 10px 30px; 
position:relative} 

#content { background: brown} 

#special {position:absolute; 
    top:0; 
    left: -30px; 
    width: 60px; 
    background: red; 
} 


var height= $("#container").css("height"); 
height = height.replace("px",""); 
height = parseInt(height) + 20; 

$("#special").css("height",height); 
+0

谢谢!这与我所尝试的非常相似。不知道我的代码为什么不起作用。但是,我现在应该可以立即开始工作。 – jimutt 2014-09-30 21:37:36

0

没有足够的信息..但也许这样的事情...

#overlap_div{ 
    position:absolute; z-index:9; left:0px, top: 0px; 
} 

,并参考容器position:relative