我正在学习CSS,我想知道为什么我们设置位置:相对即使我们没有设置具体位置,例如left: 20px,top: 10px.下面是一个css代码示例.
#home #header {
position: relative;
width: 822px;
height: 152px;
margin: 0 19px;
padding: 0;
overflow: hidden;
}
#header {
position: relative;
width: 822px;
height: 152px;
margin: 0 19px;
padding: 0;
overflow: hidden;
background: url(img/bg-content-wrap-top-int.png) no-repeat center bottom;
}
Run Code Online (Sandbox Code Playgroud)
通常是以下三个原因之一:
z-index).请参阅https://developer.mozilla.org/en/understanding_css_z-indexposition:absolute如果父母的话,里面的元素将相对于父母position:relative.见http://css-tricks.com/absolute-positioning-inside-relative-positioning/